in reply to Time::Piece reversibility
I'm using the latest Time::Piece, 1.31
I'm using 1.31_04 and at least in that, strftime works for me for your second spin (which as the only one using localtime makes sense):
#!/usr/bin/env perl use strict; use warnings; use Time::Local; use Time::Piece; my $datestr = '2017-06-19 10:07:42-0700'; print "Original date string: $datestr\n\n"; print "Using Time::Local\n"; my $time = timelocal(42, 7, 10, 19, 6, 2017); print " Epoch seconds: $time\n"; print " CORE::localtime: ", scalar CORE::localtime($time), "\n"; print "\n"; print "Using Time::Piece:\n"; print " strptime as static method:\n"; my $obj = Time::Piece->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strftime: ", $obj->strftime, "\n"; print " strptime as localtime instance method:\n"; $obj = localtime->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strftime: ", $obj->strftime, "\n"; # Has non-UTC timezone +- yay! print " strptime as gmtime instance method:\n"; $obj = gmtime->strptime($datestr, '%Y-%m-%d %H:%M:%S%z'); print " stringified: $obj\n"; print " datetime: ", $obj->datetime, "\n"; print " tzoffset: ", $obj->tzoffset, "\n"; print " hour: ", $obj->hour, "\n"; print " strftime: ", $obj->strftime, "\n";
BTW, are you aware that the 2 dates you are using are a month apart?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Time::Piece reversibility
by mla12 (Acolyte) on Jun 17, 2017 at 23:05 UTC | |
by hippo (Archbishop) on Jun 17, 2017 at 23:26 UTC |