perl - Why does my Time::Piece code give strange results? -
i trying basic comparison of 2 dates in perl. current datetime , past time correct subtraction gives incorrect results. difference should ~24 hours yet returns ~13 hours. idea why , how fix it? thanks.
use time::piece; $now = time::piece->new; $then = time::piece->strptime("2014-04-14 16:30:20", "%y-%m-%d %h:%m:%s"); $diff = $now - $then; print "current time: $now\n"; print "past time: $then\n"; print "diff in seconds:", $diff, "\n"; print "pretty diff:", $diff->pretty, "\n"; results ------ current time: tue apr 15 16:13:39 2014 past time: mon apr 14 16:30:20 2014 diff in seconds:49399 pretty diff:13 hours, 43 minutes, 19 seconds
the 2 timepoints in different timezones. difference in fact correct. can see
print $now->tzoffset, "\n"; # 7200 (i in utc +2 hence have 7200s offset) print $then->tzoffset, "\n"; # 0 so $then utc time while $now in whatever timezone environment thinks in. fix that, need decide on timezone want.
Comments
Post a Comment