Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Simple (I thought) time comparison?

by sjessie (Novice)
on Dec 20, 2016 at 00:21 UTC ( [id://1178148]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Simple (I thought) time comparison?
in thread Simple (I thought) time comparison?

Note: where I am tzoffset is -21600 (-6 hours, CST).

Replies are listed 'Best First'.
Re^4: Simple (I thought) time comparison?
by sjessie (Novice) on Dec 20, 2016 at 00:26 UTC

    And further illustrating my noob-ness, I didn't include the entire updated script so it actually made sense. Sorry. Here it is:

    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; print "The current time is $ctime\n"; print "The old time is ", $oldtime + $ctime->tzoffset, "\n"; my $halfago = $ctime - 1800; print "Half an hour ago is $halfago\n"; if ($oldtime > $halfago) { print "Old time is within a half hour\n"; } else { print "Old time is outside a half hour\n"; }
      I modified your script, so that it outputs a little more information:
      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"; }
      The parameterless form of Time::Piece's strftime includes time zone name. My output was:
      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
      Of course, since I didn't update $halfgo, it is really outside, but it illustrates davido's point.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178148]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-03-28 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found