in reply to Re^4: Simple (I thought) time comparison?
in thread Simple (I thought) time comparison?
The parameterless form of Time::Piece's strftime includes time zone name. My output was:use strict; use warnings; use Time::Piece; my $ctime = Time::Piece->new; my $oldtime = Time::Piece->strptime('Dec 19 17:44:00 2016', '%b %d %T +%Y'); $oldtime = $oldtime - $ctime->tzoffset; sub showtime { shift->strftime } print "The current time is ", showtime($ctime), "\n"; print "The old time is ", showtime($oldtime + $ctime->tzoffset), "\n"; my $halfago = $ctime - 1800; print "Half an hour ago is ", showtime($halfago), "\n"; if ($oldtime > $halfago) { print "Old time is within a half hour\n"; } else { print "Old time is outside a half hour\n"; }
Of course, since I didn't update $halfgo, it is really outside, but it illustrates davido's point.The current time is Di, 20 Dez 2016 10:09:19 Mitteleuropäische Zeit The old time is Mo, 19 Dez 2016 17:44:00 UTC Half an hour ago is Di, 20 Dez 2016 09:39:19 Mitteleuropäische Zeit Old time is outside a half hour
|
|---|