For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > January 2007 > Epoch quest









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Epoch quest
George

2007-01-30, 6:59 pm

Just a generic question about epoch.
The perl 0 time seems to be "Thu Jan 1 02:00:00 1970"
because thats what I get for
print scalar(localtime(0));

So why I have to add 1900 for getting the correct year
print (((localtime(time))[5]) + 1900);

It should be 1970 , and ((localtime(time))[5]) should
return a different (bigger number) ...



Joe Smith

2007-01-30, 6:59 pm

George wrote:
> Just a generic question about epoch.
> The perl 0 time seems to be "Thu Jan 1 02:00:00 1970"


Actually, it is 1970/01/01 00:00:00 GMT (1969/12/31 16:00:00 PST).
And it's not just perl - that epoch definition is a long-time part of Unix.

> So why I have to add 1900 for getting the correct year
> print (((localtime(time))[5]) + 1900);


Because that is how it is defined in UNIX.
For 1970 to 1999, it is a number from 70 to 99.
For 2000 to 2038, it is a number from 100 to 138.

-Joe

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com