Your sub is OK. For me it returns 7200 - GMT+2.

For calculating time delta you could take a look at Date::Calc and/or DateTime.

Update:

Perhaps calculating the time delta from the timestamps in your file(s), not from the current time? Or do i miss something?

Update2:

I'm still struggling a bit with this.

As far as i understood your timezone is GMT.

You have a file with some timestamps you think they are in another timezone, right?

And you want to know the difference between this timestamps and GMT, right?

So IMHO your sub needs the timestamps from your file as params...

Update3:

«why are timegm and timelocal returning the same epoch seconds values»

Because your box is GMT?

Update4:

Just as a little addendum (assuming you are using bash):

Karls-Mac-mini:monks karl$ date Di 14 Mai 2013 23:22:21 CEST Karls-Mac-mini:monks karl$ export TZ=UTC Karls-Mac-mini:monks karl$ date Di 14 Mai 2013 21:22:47 UTC Karls-Mac-mini:monks karl$ unset TZ Karls-Mac-mini:monks karl$ date Di 14 Mai 2013 23:23:11 CEST

Update5:

OK, this is the last one, i promise...

#!/usr/bin/env perl # delta.pl use strict; use warnings + use Time::Local; print getGMDelta() . qq(\n); sub getGMDelta { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $ltime = timelocal($sec,$min,$hour,$mday,$mon,$year); $gtime = timegm($sec,$min,$hour,$mday,$mon,$year); $rv = $gtime - $ltime; return($rv); } __END__ Karls-Mac-mini:monks karl$ export TZ=UTC Karls-Mac-mini:monks karl$ ./delta.pl 0 Karls-Mac-mini:monks karl$ unset TZ Karls-Mac-mini:monks karl$ ./delta.pl 7200

Please see also:

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Re: why are timegm and timelocal returning the same epoch seconds values by karlgoethebier
in thread why are timegm and timelocal returning the same epoch seconds values by kehansen

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.