开发者

Help with UNIX time to human time

开发者 https://www.devze.com 2022-12-21 00:45 出处:网络
I need to format a UNIX timestamp i开发者_Go百科n 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 m

I need to format a UNIX timestamp i开发者_Go百科n 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消