开发者

What's the best way to adjust for local timezones?

Maye I am wr开发者_运维知识库ong to use now() to get timestamps when storing data?

When I display date/time to the user, of course he wants to see a local time, and if he inputs time related data, rather than me using now() then he will be inputting local date/time.

Why code is getting muddled with conversations - what's the best practice for handling timestamps? UTC/locla time? How & when to adjust?


Just store all the dates in timestamp mysql column type, which can handle all timezone issues, and mysql will do all work for you.

So in the begin of your application startup all you need is to specify what timezone you need the dates belongs towith query:

SET time_zone='Asia/Vladivostok'

For example.

Also, in this case you should not get any timestamps from php, if you need to insert current time - you have to use mysql's NOW().

That's all.


Store all the dates in one time zone so they're consistent. UTC/GMT+0 is good for this.

Then use CONVERT_TZ to convert input to UTC/GMT+0 or from UTC/GMT+0 to a user's time zone.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Since all you've asked about are SQL functions, you should tag the question with the RDBMS you're using (MySQL?) instead of PHP.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜