Should the server timezone be set to UTC time?

The timestamps transmitted and stored should only be UTC time, and the time zone must be specified when displaying the time. These two principles are equally important

Following these two principles, it will not be affected by the system time zone setting

 =========================================================

First clarify the basic concepts of time and time zones:

 

The stored value of the time (UTC long) + time zone --> converted to --> the representation value of the time (local string)

 

At the same time correct a mistake that is often made, and exchange this value for: the stored value of the time (UTC long) + the time zone = the local value of the time (local long)

When transmitting and storing time values, local long is a concept that should not exist, a culprit that causes confusion, remember this!

 

When exchanging time data, if the time zone is not important or the same, then the stored value of the exchange time or the representation value of the exchange time is equivalent. If both parties are sensitive to the time zone (the representation value of different time zones needs to be displayed), it will cause confusion. The reason is usually a direct exchange of the representation value (local string) of the time or the stored value of the time, but not the time zone value.

 

Example 1:

 

For example, if the time zone of App submission logs in two countries is not important, then the performance value (string) of the submission time in the time zone of the program operator is a relatively simple and convenient solution. And if its time zone is very important, then if the time zone value is not submitted, whether it is only the storage value of the time (UTC long) or the performance value (string) of any time zone, there is no way to perfectly achieve our needs. , to put it simply, if there is confusion or contradiction, then don't worry about what value to pass, simply add the time zone field.

 

Example 2:

 

The setting of the server time zone does not affect the server time storage value, but only affects the time performance value. For servers serving multiple countries, if you set the time zone to the time zone of any country, it will cause some people's entanglement, but it doesn't matter. The important thing is that you should not save the two fields that should be time + time zone. The value is only stored as a field, and the problem is caused by the deceleration of the data, not the server time zone setting. The server time zone setting as the time representation value should be set to the time zone where the server operator is located, not any one of the many countries of the users served by the server, and similarly should not be UTC. (You have two children, and you need to divide two pears, one big and one small can't argue, will you give both pears to the kid watching the fun-UTC to solve this problem?)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272631&siteId=291194637