yeah, strftime/strptime isn't identically portable ... I've always had issue with %Z on win32 ... but DateTime's strftime/strptime is portable
#!/usr/bin/perl --
use strict;
use warnings;
use Time::Piece;
my $dt = 'Fri, 20 Sep 2024 01:14:03 UTC';
my $format = '%a, %d %b %Y %T %Z';
#~ print Time::Piece->strptime( $dt, $format );
my @date = split ' ', $dt;
my @format = split ' ', $format;
for my $ix ( 0 .. $#date ){
print "$ix ## ", "$date[$ix] == $format[$ix]\n";
print "$ix ## ", eval {
Time::Piece->strptime( $date[$ix], $format[$ix] );
} || $@, "\n";
}
exit;
__END__
0 ## Fri, == %a,
0 ## Thu Jan 1 00:00:00 1970
1 ## 20 == %d
1 ## Tue Jan 20 00:00:00 1970
2 ## Sep == %b
2 ## Tue Sep 1 00:00:00 1970
3 ## 2024 == %Y
3 ## Mon Jan 1 00:00:00 2024
4 ## 01:14:03 == %T
4 ## Thu Jan 1 01:14:03 1970
5 ## UTC == %Z
5 ## Error parsing time at C:/citrusperl/site/lib/Time/Piece.pm
+line 469.
-
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.
|