Why should I use UTC?

Currently, our application uses local time, not UTC. I know that it is important to use UTC, but I canโ€™t remember why.

Assuming that DateTimes are stored with an offset, when comparing local time with UTC time or with another time with a different time zone, of course, will any library used know about different time zones and mutate two objects into something that can be compared?

As long as the offset is passed using DateTime (for example, it will use objects, not strings), I don't understand why this matters. Why should I deal with 2014-09-01T13:44:13+00:00 and not 2014-09-01T14:44:13+01:00 ? In fact, saving as UTC loses offset information (local time when the time was announced).

What am I missing here?

Context: we have limited errors individually, and I thought: โ€œaha: move all things to UTCโ€, but then I realized that I was just looking at the code converting a bunch of DateTime objects to use the UTC timezone, and it seemed empty to me a waste of time.

+5
source share
3 answers

Your use case allows you to store local time with an offset. There is no need to store IMO in UTC, since you can always translate a point in time to any other local time. In fact, this gives you even more, since you have additional information about local time.

Technically, there is an advantage to storing dates as UTC and offsets separately: you can sort the string, which gives you an advantage, for example. DBS that do not properly support date fields with offsets (e.g. MySQL).

If you are considering systems that do not allow storing bias, actors will need to agree on a common time zone. UTC seems to be a very stable candidate with good time translation support.

One example of this is Exif , where you can only store the local date without any time zone information. Another example is a hardware clock on a computer with multiple operating systems. If the actors disagree with the common time zone, you will have headaches (Linux and Windows can become fun when switching DST).

+5
source

There are two reasons why I keep time as UTC.

The first is that with the global users of some of the applications I'm working on, the local time depends on the user, so the local time for the user who entered the data may not be the local time for the user who is viewing the data later.

Secondly, time intervals change. They submit to the whims of governments. That UTC +5 today may be tomorrow UTC +6, simply because some governments say it will then make the local time + offset different from what was saved. You can always determine the correct local time, but I just see it as more work than just converting UTC to local.

These are the best reasons I know for using UTC, but I'm sure there are others that I haven't thought about.

+4
source

I think it is best to store DateTIme + Offset

The point is that you should always store the DateTime either in UTC or with an offset, but never save the DateTime "local centric" or without an offset. In other words:

Best! DateTime + Offset

 2014-09-03 11:36:07 EDT -04:00 

Good UTC:

 2014-09-03 15:36:07 UTC 

Veryyyyy bad: DateTime no offset

 2014-09-03 11:36:07 

For example, this can happen if you really do not care about the time zone, and at the end the previous time can be saved as:

 2014-09-03 11:36:07 UTC 

Now, depending on your language environment, it may happen that you may need to convert DateTime / Offset to something else, but my advice is to always keep it as the first form ....

+1
source

Source: https://habr.com/ru/post/1201738/


All Articles