Re: time() off
by gellyfish (Monsignor) on Sep 09, 2004 at 14:20 UTC
|
c:\> SET TZ=EST4
C:\> perl -e"print scalar localtime()"
?
I suspect that your OS has broken timezone handling (you don't say what it is though.) /J\
| [reply] [d/l] |
|
|
That fixed it. For whatever reason I had a system variable TZ and it was set to EST. Changing it to EST4 worked and my perl time is back! Thanks guys.
| [reply] |
Re: time() off
by bart (Canon) on Sep 09, 2004 at 13:42 UTC
|
time() returns epoch time, which would be the same (for your type of OS) all over the world. It has no idea about GMT. It's just a number, the number of seconds passed since a reference date, commonly 1.1.1970 at 0:00:00, GMT. That's a moment in time in history, expressed in GMT.
You're probably using gmtime() in your conversion to string, while you should be using localtime() instead.
my $time = 1094736647;
print scalar gmtime($time);
print "\n";
print scalar localtime($time);
| [reply] [d/l] |
Re: time() off
by edan (Curate) on Sep 09, 2004 at 13:46 UTC
|
The perl time function returns epoch time, which is likely to be (except on strange sysmtems) "the number of non-leap seconds since 00:00:00 UTC, January 1, 1970" That means it's in "GMT" (or UTC) time. If you want the local time, you want to feed the value of time to the (conveniently named) function localtime. If you want that pretty string like "Thu Sep 9 09:31:13 2004" then call localtime in scalar context. If you have more specific formatting needs, I would use POSIX::strftime().
| [reply] |
|
|
ok, understood, about time(), but localtime is still off, its not 1:48 in florida right now its 9:48
my localtime() returns Thu Sep 9 13:48:38 2004, and that's wrong. what will fix that?
| [reply] |
|
|
ok, so maybe I'm just not getting it...Does localtime simply return time in a nice format?, and not the actual "Local Time" of your system? if so I get it, I think thats dumb, but I get it...If localtime is actually supposed to return the "Local time" of my stytem then its off. Please clarify.
| [reply] |
|
|
Re: time() off
by osunderdog (Deacon) on Sep 09, 2004 at 14:25 UTC
|
I've seen something similar if the environment variable 'TZ' is set. This is consistent on both *nix and Windows:
F:\>perl -e "print scalar localtime"
Thu Sep 9 08:18:24 2004
F:\>set TZ=MST
F:\>perl -e "print scalar localtime"
Thu Sep 9 14:19:25 2004
And on *nix:
$perl -e "print scalar localtime"
Thu Sep 9 08:20:26 2004
$export TZ=mst
$perl -e "print scalar localtime"
Thu Sep 9 14:20:35 2004
| [reply] [d/l] [select] |
Re: time() off
by mutated (Monk) on Sep 09, 2004 at 13:58 UTC
|
I'm assuming you are running on a *nix what does the command date return? How are you setting your system clock? and what is /etc/localtime symbolicaly linked to?
| [reply] |
|
|
No unfortunately I don't have the luxury here at work to get to use Nix, I'm on MSWin32, using ActiveState perl, v5.8.4, my system clock and BIOS Clock are both correct, and my regional settings are set to United States
| [reply] |
Re: time() off
by rupesh (Hermit) on Sep 09, 2004 at 13:38 UTC
|
C:\>perl -e "print scalar localtime();"
Thu Sep 9 19:07:14 2004
| [reply] [d/l] |
|
|
And the point of that was?...My localtime is off too...
perl -e "print scalar localtime();" = Thu Sep 9 13:42:34 2004
and its not 1:42 pm right now...
| [reply] |
|
|
The point of that was (I would guess) to point out that time() is supposed to be UTC-based, with gmtime and localtime available to display it according to your whim. It's only now that we hear that localtime() is giving you a problem.
| [reply] |
|
|
| [reply] |