开发者

Store UTC date time in database

开发者 https://www.devze.com 2023-01-17 14:36 出处:网络
I will convert all date & time input by user (local time) to UTC and store it in database. When display back I will convert UTC time to their time zone which is set in t开发者_StackOverflow中文版h

I will convert all date & time input by user (local time) to UTC and store it in database. When display back I will convert UTC time to their time zone which is set in t开发者_StackOverflow中文版heir profile. Is it good?


I think it's good enough. Besides storing user timezone in profile, you can also let client (for example, javascript) convert UTC time according to user computer time zone.


As long as you can convert to/from any time zone from your stored DB records, that's all you need.

What you've described will work.


Note some MySQL documentation in regards to timezone & server/client workings:

Per-connection time zones.
Each client that connects has its own time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:
mysql> SET time_zone = timezone;

So, normally, in your proposed solution, all is right, but don't let the actual server or client timezone changing catch you of guard.

0

精彩评论

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

关注公众号