开发者

PHP - How to cater for timezone

I have setup a web app for a client. The server is in US I believe. The client 开发者_运维百科himself is in Sydney.

He says he added a record to a table with a timestamp field and it shows the timestamp as 2010-11-19 07:12:00 but the actual local time has been 2010-11-20 13:12:00. So he is 30 hours ahead of the time recorded. This doesn't look right, how could the offset be greater than 24 hours? And what should I change/use so he sees correct date/time?

Edit:

Would it be correct approach to add 30 hours to current time before inserting the record?


First thing is to check the time on the server. Make sure that is correct.

To fix the issue, you have to know the offset for the user, so this will either need to be a recorded in a user profile, or if it is stationary for the whole application, you can set the server's time to correspond with his timezone.

Another option is using PHP's DateTime Class.

Another option would be to use certain Timezone Setting functions PHP offers.

A final option would be to set the timezone setting for MySQL this requires you to add items to the startup options, so you will need to edit the startup script for MySQL.


If the offset is 30 hours, then the culprit can't possibly be the time zone. Or at least, it can't be the only culprit. Without more details, that's the best I can do.


Sydney, Australia is GMT+10. The east coast of the US is GMT-5. That's a 15 hour difference.

Could be a coding error, where the timezone is getting corrected twice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜