Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by karlgoethebier (Parson)
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»

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033551]
help
Chatterbox?
[shmem]: no. You're right.
[msh210]: About time... last time I was right was... I don't even remember when.
[shmem]: perl -e 'warn "test$/", ^@^ '
[Eily]: well, at least it's right about warn doing the same thing as die :)
[shmem]: same with undef as last element
[msh210]: oh, good point. It's the best kind of correct
[shmem]: msh210: but I'd not call it a lie outright. That's when you do know the truth.
[msh210]: I don't have sendmail (I'm on MS Windows), so does one of you think you can report the bug?
[shmem]: msh210: 'tis about time to tell the sad truth to perl5porters - via perlbug
[msh210]: probably whoever wrote that actually knows the truth

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2017-04-24 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (439 votes). Check out past polls.