GMT UTC CST ISO summer time timestamp, what the hell are they?

GMT UTC CST ISO summer time timestamp, what the hell are they?

Hello, my name is Brother A (YourBatman).

Date/time processing is a very common scenario in normal development. If it’s just a simple formatting scenario, it’s okay. Once it involves time zone, cross-regional and cross-time zone time conversion scenarios, even when there are GMT time, UTC time, etc. When stacking concepts are piled up, they are always mentally frustrated and unable to resist.

In the context of the information age of the global village, there are more and more multinational corporations/multinational companies doing business, so the probability that our programmers encounter date/time conversion/display between different time zones has greatly increased. For example: when you place an order on an e-commerce platform, it’s ok to show Beijing time to the Chinese page, but you can’t show Beijing time to Americans, right? Otherwise, Americans see that many orders are placed at 1 or 2 in the morning, and they think it’s a bad bell at midnight.

GMT UTC CST ISO summer time timestamp, what the hell are they?

Java used the Date type to represent the date/time before version 8. Since version 8, the JSR 310 date/time type has been introduced. The two systems have different processing methods for local time, time zone time, and time zone formatting.

Brother A recently engaged in a production accident due to the problem of cross-time zone date conversion . For this, I learned from the pain and decided to organize the experience into a document. The purpose is to never step on this pit in the future and to help everyone at the same time.

This part will be divided into two articles:

  1. Concepts: Popular science concepts and backgrounds such as GMT, UTC, time zone, timestamp, daylight saving time, etc.
  2. Actual combat article: On the basis of 1 (the concept must be known first, otherwise the actual combat cannot be carried out), how does Java deal with GMT/UTC time, time zone, offset, daylight saving time...

After finishing these two articles, I no longer have to worry about burying bugs in date/time. Believe me, these two articles are very collectible .

Outline of this article

GMT UTC CST ISO summer time timestamp, what the hell are they?

Version convention

  • JDK:8

✍Text

The following topics will focus on some date/time concepts. You have heard these terms without exception, but I guess you probably don’t understand or even know the difference.

GMT: Greenwich Mean Time

Greenwich (also known as: Greenwich) time, also called Universal Time (Universal Time), also called Universal Time. It refers to the standard time of the Royal Greenwich Observatory in the suburbs of London , England , when it is on the prime meridian, and is the zone time of time zone 0 .prime meridian

As we all know, the Beijing time used by the Celestial Dynasty is located in Dongba District (+8), which is 8 hours away from the standard time. What does it mean? For example: if GMT (Greenwich, London, UK) is now 11 am, then China Beijing time is now 11 + 8 = 19 o'clock (7 pm).
GMT UTC CST ISO summer time timestamp, what the hell are they?

Abstracting this formula again, it can be expressed as: local time = GMT + time zone difference
GMT UTC CST ISO summer time timestamp, what the hell are they?

Beijing is located in the East Eight District, the time zone difference is N=+8, and New York is located in the West Fifth District, the time zone difference is N=-5. Such a calculation, if Beijing time is 23 o'clock at night, it is time to New York the same day 10:00 (23--8--5 = 10)

Why is Greenwich as standard time?

You might ask, everyone has a lumbar disc, why is it so prominent in Greenwich?

The general background is like this: since the 19th century, countries around the world began to communicate frequently, and the European, American and Asian continents all have their own time zones. In order to improve communication efficiency and avoid confusion, representatives of various countries held an international conference in Washington, USA in 1884. At the conference, Greenwich, London, England was selected as the center of global time , and it was responsible for maintenance and calculation. Since 1924, the Greenwich Observatory will broadcast time to the world every hour (as of 1979).

It’s quite funny to have a meeting in Washington, U.S. and determine London, England as the center of time. O(∩_∩)O haha~

In fact, the main reason for choosing Greenwich, England was that most of the ships at that time had already used the Greenwich Meridian as the reference standard. After all, the British used to be an empire that never sets in the sun. At the end of the great nautical era, they began to dominate the world. regime.

The Greenwich Observatory's authority in the field of timekeeping is very large, such as the nearest "time storm" to us: when the century is about to cross, countries around the world are arguing whether the 21st century should start in 2000 or 2001. In the end, the Greenwich Observatory came forward to settle the dispute and opened a press conference to announce that the 21st century began in 2001 .
Greenwich Observatory (old site)

Earth rotation

Earth around the rotation axis from west to east rotation (east sun goes down), so the people of East time zone than the time zone of the West who earlier Some see the sun, so that the time will be a little earlier.

GMT UTC CST ISO summer time timestamp, what the hell are they?

Taking the prime meridian as the center and dividing a time zone every 15° of longitude according to the rotation direction of the earth, the world is divided into 24 time zones: East 1 to East 12, West 1 to West 12, of which 12 are east and west. The zone span is 7.5°, also called half-time zone.

What time zones are there in China?

One, this is a reasonably wrong answer. It is reasonable because although China has a vast territory, the country uses a unified Beijing time, so it is easy to be mistaken for only one time zone.

It's wrong because you can tell by just thinking about it. How can China only lie in one time zone? The correct answer is: Mainland China spans 5 time zones, and the approximate directions of each time zone are as follows:

GMT UTC CST ISO summer time timestamp, what the hell are they?

Looking at the picture, you can clearly know why the Tianchao chose Dongba District time as the national standard time, right? That's right, just because Beijing is in the East Eighth District, even if the map is only the size of a bullet, it is so grandiose.

It is indeed much more convenient for China to use unified time for communication, which reduces a lot of unnecessary troubles. But it also brings some "small problems". For example, my friend in Xinjiang (located in East 5/6 District) is actually 2-3 hours behind the Beijing time in East 8 District , when we are ready to finish dinner at 7 o'clock normally. , Xinjiang is still shining in the sky, quite interesting~

What time zones are there in the United States?

When it comes to time zones, we have to mention America that plans to be great again. The United States has the same vast territory, spanning 4 time zones:

GMT UTC CST ISO summer time timestamp, what the hell are they?

As shown in the picture, there are a total of four time zones, divided according to the colors in the picture (not strictly divided, otherwise it will be embarrassing if the time next door to the same cell is 1 hour later than you), from right to left:

  1. Eastern Time Zone (ET) : West 5th District, representative cities: Washington, DC, New York, Miami, etc., also known as New York time. Beijing Time = ET + 13h
  2. Central Time Zone (CT) : West 6th District, representative cities: Chicago, Houston, etc. Beijing Time = CT + 14h
  3. Mountain Time Zone (MT) : West 7th District, representative cities: Denver, Phoenix, etc. Beijing Time = MT + 15h
  4. Pacific Time Zone (PST) : West 8th District, representative cities: Los Angeles, Las Vegas, Seattle, etc. Beijing Time = PST + 16h

The origin of GMT and Http protocol

This is a point of knowledge that I "ran into", and I will share it with you here.

Http 1.1 protocol has strict regulations on the date and time transmission format, and supports the following three formats:

GMT UTC CST ISO summer time timestamp, what the hell are they?

The first format is the standard format for Internet transmission , which is also the current standard. The 2 and 3 types are purely designed to be compatible with Http 1.0. Now they are basically eliminated and no one will use them again. So in fact, there is only the first type. As an experienced programmer, you should be familiar with this format.

In addition, there is another key knowledge point: all HTTP date/time stamps must be expressed in Greenwich Mean Time (GMT), no exceptions . For HTTP, GMT is completely equal to UTC (Coordinated Universal Time).

Of course, all of this is done automatically by the browser for you. After all, the Http protocol is done by the browser.

UTC: Coordinated Universal Time

Coordinated Universal Time is literally translated as: Coordinated Universal Time. It uses atomic time as the unit of measurement, and the calculation result is extremely rigorous and precise. It is more accurate than GMT time. The error value must be kept within 0.9 seconds. If it is greater than 0.9 seconds, it will be "solved" by leap seconds .

GMT UTC CST ISO summer time timestamp, what the hell are they?

Atomic time: A time measurement system based on the electromagnetic oscillation frequency emitted by the atoms of matter. The Physics Experiment City in the United States built the most accurate atomic clock in human history in 2014, with an error of 1s in 5 billion years , which is quite reliable. China's cesium atomic clock can also ensure that the error of 20 million years does not exceed 1s.

Memorabilia: The World Administrative Radio Conference in Neiva in early December 1979 passed a resolution to replace "Greenwich Mean Time (GMT)" with "Coordinated Universal Time (UTC)" as the international standard time in the field of radio communications .

The difference between UTC and GMT

UTC and GMT are both referred to as the universal standard time. Since Mao had GMT, he also came up with UTC. What is the difference? The following is a brief description.

GMT : The old time measurement standard. Time is calculated based on the rotation and revolution of the earth. One rotation is one day, and one revolution is one year. However, the orbit of the earth's revolution is elliptical:

GMT UTC CST ISO summer time timestamp, what the hell are they?

And later people discovered that the rotation time of the earth is not constant. This will cause one day to be longer and one day to be shorter. The larger the error makes people feel that the time is not so "precise", so it is urgent. Need a more accurate plan to time, UTC was born.

UTC : In 1967, humans produced an atomic clock, thus "inventing" UTC time and officially put it into use. It is standard time in the true sense. It is based on the second defined by the atomic clock. UTC time considers that a solar day (one day) is always a constant 86400 seconds (24 hours).

GMT UTC CST ISO summer time timestamp, what the hell are they?

UTC is coordinated time, meaning: everything is based on me, and all are in line with me . So there is nothing wrong with calling it Universal Standard Time, and it is more appropriate to call GMT the local time in Greenwich (also called the old standard time).

UTC and GMT connection

Because in most cases, UTC time can be interchanged with GMT time. Many classmates are confused about this. Isn't they the same?

Actually not. Here is an easy-to-understand sentence to inform them of the connection: UTC is the standard time reference, like GMT (Greenwich Mean Time), ET (Eastern Time), PST (Pacific Time), CST (Beijing Time), etc. They are all specific time zones. GMT can be directly converted to UTC, just because it happens that GMT is 0 time zone time, and the value is exactly the same as UTC (the two can be regarded as equal if it does not need to be accurate to the second), it looks the same, but the conceptual meaning Please be sure to distinguish between them.

UTC and offset

In daily life, the time we use must be local time . When there is only GMT, the local time is calculated by the time zone, and now UTC is the standard reference, so the local time is expressed in the form of UTC and offset:

GMT UTC CST ISO summer time timestamp, what the hell are they?

This offset can be expressed as: UTC -or UTC +, followed by 小时数,分钟数. For example: UTC +9:30 means Australia Central Standard Time, UTC +8 means China Standard Time. Offset common representation are: ±[hh]:[mm], ±[hh][mm], ±[hh]these three methods can be.

For example: the UTC time is now 10:30z(z means offset = 0), then if Beijing time is now 1630 +0800(4:30 pm), the corresponding New York time is 0530 -0500(5:30 am).

Note: In the UTC world, there is no concept of time zone, but offset (time point up to the offset is a regular UTC time), it has no direct relationship with time zone

It can be seen that the offset can be controlled to the minute level, which is very refined. There are only 24 time zones in the world (only accurate to the hour), but there are "unlimited" offsets. Of course, in order to facilitate communication, the Time and Date Alliance summarized the offsets of major countries/cities in the world and gave them a Time zone namename for communication. There are hundreds of them. Some screenshots are as follows:

GMT UTC CST ISO summer time timestamp, what the hell are they?

For the full correspondence between the offset and the country/city name, please refer to the URL (direct access, no need to ***): https://www.timeanddate.com/time/zones

CST

The embarrassing thing about the acronym CST is that it can represent four different times at the same time:

  • CST (China Standard Time): China Standard Time UTC+8:00
  • Central Standard Time (USA) UTC-6:00
  • Central Standard Time (Australia) UTC+9:30
  • Cuba Standard Time UTC-4:00

The meaning of CST depends on how to translate it, so you need to make your own choice based on the context.

ISO

In terms of time and date, its full name is ISO 8601, which is a standard for date/time representation. Provides a clear and internationally understandable calendar and clock format.

GMT UTC CST ISO summer time timestamp, what the hell are they?

This ISO standard helps to eliminate the impact of various Japanese-Japanese conventions, cultures and time zones on global business. It provides a way to display the date and time, which is clearly defined and understandable to both humans and machines. When dates are represented by numbers, they can be interpreted in different ways. For example, 01/05/12 can represent January 5, 2012 or May 1, 2012. On a personal level, this uncertainty can be very frustrating, and in a business environment, it can be very expensive. In the case of unclear dates, it is very difficult to organize meetings and deliver, write contracts and purchase air tickets.

ISO 8601 representation through the development of an internationally recognized date to resolve this uncertainty: YYYY-MM-DD. For example, September 27, 2012 will be represented as 2012-09-27.

Many development languages ​​have built-in commonly used ISO standard date/time formats, such as those in Java:

  • ISO.DATE:yyyy-MM-dd, e.g. "2000-10-31"
  • ISO.TIME:HH:mm:ss.SSSXXX, e.g. "01:30:00.000-05:00"
  • ISO.DATE_TIME:yyyy-MM-dd'T'HH:mm:ss.SSSXXX, e.g. "2000-10-31T01:30:00.000-05:00".

summer time

DST (Daylight Saving Time), summer time is also called summer time (but there is no winter time). It is a system of artificially setting local time in order to save energy (encourage people to go to bed early and get up early, do not waste electricity, and use natural resources as much as possible for long summer sunshine). About 40% of countries around the world use daylight saving time in summer, and other countries use daylight saving time throughout the year. Only use standard time. Representative countries that are using daylight saving time: United States, European Union, Russia, etc.

GMT UTC CST ISO summer time timestamp, what the hell are they?

The daylight saving time period is different every year (usually starting on the second Sunday of March). For example, the daylight saving time in the United States in 2020 is: March 8, 2020-November 1, 2020. The specific method is: dial the clock forward for 1 hour on the 3.8 day, and restore it on the 11.1 day.

China did it for a short period of time between 1986 and 1992, but it was "abandoned" if it was too troublesome.

Memorabilia: Currently, nearly 110 countries around the world implement daylight saving time every year. Since March 27, 2011, Russia has been using daylight saving time permanently . The time has been advanced by one hour and will not be adjusted back.

Timestamp

In the real life world, time is constantly moving forward. If we look forward to the starting point of time, it may be when the universe was born or before the universe appeared, but it must be something we cannot find at present. We don’t know the distance to time. The precise distance from the origin. So if we want to express time, we need to artificially define an origin. It is: Greenwich Mean Time (GMT) January 1, 1970, midnight 0:00:0.

Timestamp generally refers to the UNIX time, or the time representation used by UNIX-like systems (such as Linux, MacOS, etc.). Defined as: 1970-1-1 0:0:0the total number of seconds from UTC time to the present (second is the general term for milliseconds, microseconds, and nanoseconds).

GMT UTC CST ISO summer time timestamp, what the hell are they?

But a case that cannot be ignored: due to the existence of leap seconds, when a leap second occurs, it is very likely that the same time stamp represents two moments (similar to a clock callback), and the leap second is not regular, so it cannot How to avoid procedural avoidance?

At this time, a special time synchronization protocol is needed to ensure that it is: network time protocol.

Network time protocol

Network Time Protocol (NTP) is a protocol used to synchronize computer time. It can synchronize the computer to its server or clock source (such as quartz clock, GPS, etc.), and it can provide high accuracy Time correction (the difference between the LAN and the standard is less than 1 millisecond, and tens of milliseconds on the WAN), and can be encrypted and confirmed to prevent malicious protocols***.

The purpose of NTP is to provide accurate and robust time services in a disorderly Internet environment. All major operating systems (windows/Linux) implement NTP.

✍Summary

To put it simply, GMT Greenwich Mean Time can be regarded as the previous standard time, while UTC time is the world time standard in use now; the time zone is divided by the prime meridian as the center. East is positive and west is negative. The virgin meridian is located in Greenwich, London, England; daylight saving time is a local time system (not a global standard). Where daylight saving time is implemented, there are two special days a year, that is, there are only 23 hours in one day and 25 in another day hour.

A thorough understanding of these concepts from the source will make us more powerful in dealing with time-related issues. This article introduces a lot of date/time concepts, and there is too much text, so it is recommended that you collect them as a reference book.

The next article will follow the content of this article, from a practical perspective, introduce how Java implements GMT and UTC time, as well as the use and avoidance guides in various cases. Welcome to follow me.

♨This article thinking questions♨

After reading it, you may not understand it, and you may not understand it. Here, 3 thought questions at the end of the article will help you review:

  1. Is China in the Southern Hemisphere or the Northern Hemisphere? Eastern or Western hemisphere?
  2. What is the difference and connection between GMT time and UTC time?
  3. Does China have daylight saving time?

☀Recommended reading☀

♚Statement♚

This article belongs to the column: Java advanced , you can get all the content by replying to the column name in the background of the public account.

Share, grow, refuse to hide and stop. Pay attention to [BAT Utopia], and reply to the keyword column with small and beautiful original columns such as Spring technology stack and middleware for free learning. This article has beenhttps://www.yourbatman.cn included.

This article is an original article by Brother A (YourBatman), and cannot be reproduced without the author's permission/opening. Thank you for your cooperation.

Guess you like

Origin blog.51cto.com/3631118/2596419