Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: why are timegm and timelocal returning the same epoch seconds values

by karlgoethebier (Curate)
on May 14, 2013 at 20:40 UTC ( #1033551=note: print w/ replies, xml ) Need Help??


in reply to why are timegm and timelocal returning the same epoch seconds values

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»


Comment on Re: why are timegm and timelocal returning the same epoch seconds values
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-10-21 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (96 votes), past polls