开发者

Should DateTime be stored in UTC or local time(of server) in a website that is accessible all over the world

What is the impact of the system like shopping cart in wh开发者_高级运维ich one customer(buyer) sits in one timezone and the other(seller) is on other timezone and the date is changed at one end. so the report data for one customer who bought is different than the other?


If it represents a point in time, you should definitely use UTC. That sounds like the right choice in this particular case.

In some other cases, you want to store the local time - for instance, to represent an alarm which should go off at 8am in the local time, whatever time zone the user is in. This is usually useful for calendaring applications... and you're not storing a single point in time here.

One concrete example of why it's worth storing points in time in UTC is that local times can be ambiguous due to daylight saving transitions - if the clock goes back from 2am to 1am, there'll be a local time of 1:30am twice. In UTC, there's no such ambiguity.


UTC forever! Seriously, it means you don't have to mess with daylight savings (or locality) adjustments in your model, only in the view.


The biggest "Pro" of using UTC is that if you choose to go with it then you can always be sure dates are stored that way and never have to doubt yourself. This saves a lot of hassle.


i think,stored is not biggest problem,the most important is when set to some client like WEBSITE,API ...etc,you must send as UTC+0 format,maybe long type is better?


UTC. I know a user in another forum that was storing local time from the end-user PC and some of the users decided that they didn't need auto adjust for DST. They are very sad now.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜