tags:

views:

61

answers:

2

I need to format a UNIX timestamp in GMT format to a local date/time. I'm using gmstrftime to do this and I can get the correct result if I use an offset. I just so happen to know what my offset is for the pacific timezone but I don't want to have to get the correct time like this. I've used date_default_timezone_set so gmstrftime is reporting the correct timezone but the time is off by like a day.

I don't get it. If gmstrftime knows what timezone I'm in, why is the time off?

+1  A: 

If you have the correct timezone set (such as with date_default_timezone_set) then you only need to use date() for the formatting, no extra coding. UNIX timestamps are in GMT by definition of a UNIX timestamp -- number of seconds since January 1, 1970 00:00:00 GMT.

Dan Grossman
Your absolutely correct Dan, thanks. Why does PHP have umteen million time functions? I can't seem to ever get what I need.
jim
A: 

gmstrftime will always return the time as UTC, seems like you want strftime.

Anders Lindahl
Thanks for the answer Anders. I need to read up on that function. I've never used it before.
jim