Page 1 of 1
Unix Time Problem
Posted: Tue Dec 14, 2010 4:21 am
by spacebiscuit
Hi,
I'm having some trouble with formatting a Unix time stamp. I am retreiving a timestamp from a MySQL database, for example:
1292318785 - Tue, 14 Dec 2010 09:26:25
I am formatting this using:
However this outputs:
3:26:25 - which is 6 hours behind. It seems there is an offset?
Any advice would be apprecaited.
Thanks,
Rob.
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 4:26 am
by Darhazer
the output depends on the server timezone / timezone set in php.ini
You can use gmdate() however to get timezone-independent output
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 5:00 am
by klevis miho
Use the date_default_timezone_set function in the beginning of the script.
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 5:27 am
by spacebiscuit
Thanks that fixed the problem - i'm not quite sure why it is necessary though. The time has already been stamped and stored, I could understand if I was grabbing the curent live time and I wanted this to be correct for each user but that is not the case here.
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 5:33 am
by klevis miho
Yes but the timestamp "1292318785" is relative to the server.
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 6:35 am
by spacebiscuit
I thought a unix timestamp was relative to Unix rather than the server?
Rob.
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 7:13 am
by klevis miho
It's the number of seconds from January 1970 till now, but the "now" depends on the server.
Re: Unix Time Problem
Posted: Tue Dec 14, 2010 9:51 am
by pickle
The timestamp is in GMT. So a timestamp of 0 on a server in Chicago would be January 1, 1970 minus 7 hours.