Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm finding something of an inconsistent behaviour when using DateTime::Format::Strptime.

The program as shown below illustrates the problem... but in short, the parsing of an 'hh:mm:ss p' format on a 12-hour clock doesn't seem to work with a 'PM' included in the string. Using a 24-hour clock format (and no 'PM') seems to work Ok... but my data isn't presented in that format.

An example program:-

use strict; use warnings; #use diagnostics; use DateTime; use DateTime::Format::Strptime; our $LocalTZ = DateTime::TimeZone->new( name => 'local' ); my $dtnow = DateTime->now(time_zone => $LocalTZ); # Current *local* + time printf("\$dtnow: !%s!\n", $dtnow); my $lo = "18/03/2019 10:12:53 am"; # Always works my $hi = "24/03/2019 3:15:00 pm"; # Does not work... the format I + need to use # my $hi = "24/03/2019 03:15:00 pm"; # Does not work # my $hi = "24/03/2019 3:15:00 pm"; # Does not work # my $hi = "24/03/2019 15:15:00 pm"; # Works but 15hrs with 'pm' i +s silly # my $hi = "24/03/2019 15:15:00"; # Works my $dmy_fmt = DateTime::Format::Strptime->new( # Let DateTime use 'dd +/mm/yyyy' pattern => '%d/%m/%Y %H:%M:%S %p', # pattern => '%d/%m/%Y %H:%M:%S', # Use this when no 'am/pm' + in the date string time_zone => 'Australia/Victoria', # time_zone => 'local', ); my $lodt = $dmy_fmt->parse_datetime($lo); printf(" \$lodt: !%s!\n", $lodt); my $hidt = $dmy_fmt->parse_datetime($hi); printf(" \$hidt: !%s!\n", $hidt);

I have updated the modules to the latest versions via CPAN... but it doesn't make any difference. Otherwise, I'm talking about ActiveState Perl v5.16.3 Build 1603, running under Windows 10 64-bit.

Any clues on what's wrong here... with what I'm trying to do OR with the ways the functions are working?

Thanks a heap for any forthcoming suggestions.


In reply to DateTime::Format::Strptime Parsing Seems to have a Problem? by ozboomer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found