Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 which 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?

like image 515
Adeel Avatar asked Jan 20 '10 08:01

Adeel


2 Answers

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.

like image 174
Jon Skeet Avatar answered Nov 14 '22 08:11

Jon Skeet


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

like image 39
Chris Jester-Young Avatar answered Nov 14 '22 08:11

Chris Jester-Young