XP is just a number 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??

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»

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 [download] 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
[download]

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Create A New User
Node Status?
node history
Node Type: note [id://1033551]
help
Chatterbox?
 [choroba]: needed everywhere, available rarely [LanX]: Question: starting a script from an icon in Windows, but after C-c the window closes ... what I want is to restart in the cmd.exe. Recommendations? [Corion]: LanX: What do you mean by "restart in the cmd.exe" ? [Corion]: Do you want to launch a script and keep the command prompt/console window open? [Corion]: Do you want to wait for a key press before closing the window? [LanX]: I want the command line in the history [tye]: -Mouse [Corion]: Option a) would mean launching cmd.exe /k c:\path\to\ batchfile- launching-perl- script.cmd. Option b) would be to add pause as the last line of said batch file.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2017-03-27 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (320 votes). Check out past polls.