Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use UTC?

Our app currently uses a local time rather than UTC. I know that it's important to use UTC, but cannot for the life of me remember why.

Assuming that the DateTimes are stored with an offset, when comparing a local time to a UTC time, or with another time with a different timezone, surely any library worth using will know about the different timezones and mutate the two objects into something that can be compared?

As long as the offset is passed around with the DateTime (which it will be using objects rather than strings, say), I do not see why it matters. Why should I deal with 2014-09-01T13:44:13+00:00 rather than 2014-09-01T14:44:13+01:00? In fact, storing as UTC looses the offset information (the local time when the time was declared).

What am I missing here?

Context: We are having limit, off-by-one style errors, and I thought 'aha: move all the things to UTC' but then realised that I am just going through the code converting a bunch of DateTime objects to use a UTC timezone, and this struck me as a waste of time.

like image 237
sennett Avatar asked Sep 03 '14 14:09

sennett


People also ask

Why we should use UTC?

Universal Coordinated Time (UTC) is the basis for modern timekeeping. Among other things, it provides a common baseline for converting between incremental and local time. The time zone offset for UTC is 0. UTC is often indicated in field-based formats using Z .

Should you use UTC time?

UTC Is the Standard It's important to know if you ever work with people in other time zones, but also interesting for its own sake. Hopefully, it will be a long time before there's another major time standard shakeup. In the meantime, you can at least make sure your computer's time is accurate!

Should I use GMT or UTC?

GMT is a time zone officially used in some European and African countries. The time can be displayed using both the 24-hour format (0 - 24) or the 12-hour format (1 - 12 am/pm). UTC is not a time zone, but a time standard that is the basis for civil time and time zones worldwide.

Should I store dates as UTC?

It is important that there is consistency across all your date-related data. When storing dates in the database, they should always be in UTC. If you are not familiar with what UTC is, it is a primary time standard that all the major timezones are based on. The major timezones are just offsets from UTC.


1 Answers

There are two reasons that I store time as UTC.

First, is that with global users of some of the applications I work on, local time varies per user, so local time for a user that entered the data may not be local time for a user viewing the data later.

Second, timezones change. They are subject to the whims of governments. What is UTC +5 today could be UTC +6 tomorrow just because some government says so, which would then make the local time + offset different than what was stored. You can always figure out the correct local time, but I just view it as more work than just converting UTC to local.

Those are the best reasons that I am aware of for using UTC, but I am sure there are others I haven't thought of.

like image 181
Nick Zimmerman Avatar answered Sep 19 '22 07:09

Nick Zimmerman