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.

In reply to Re^5: Simple (I thought) time comparison? by soonix
in thread Simple (I thought) time comparison? by sjessie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.