preface

Recently the reconstruction of the old project, the work is really busy, the old project code really let a person a long story……

I haven’t written for a long time. Today I’m going to learn about time zones.

Probably most of my friends and I used to do domestic projects, the default time zone is Beijing, so there is no need to consider this problem. But now the new company is doing overseas projects, so it is necessary to know the time zone. I hope this article will familiarize you with time zones.

Why jet lag

If I were to ask you what time it is, what would you say? “It’s nine o ‘clock in the morning and the sun is just right!” “By default, you set it to Beijing time because it’s 4 a.m. in Moscow, Russia, and the sun hasn’t come up yet. Since the Earth rotates from west to east, the east sees the sun before the west, so the time in the east is earlier than in the west. As a result, countries in different parts of the earth have time differences, and the farther away the country is from east to west, the greater the time difference.

Why is there time zone

If you took a geography class in high school, you should know. We mentioned earlier that the east sees the sun before the west, so each meridian has a different position to see the sun, which leads to a different time on each meridian. So the concept of time zones was created to make it easier to calculate time in different parts of the world.

Time zone division

You may never think about obsoletezones, but if you think you’re working on a domestic project and you don’t use time zones, you’re wrong. Because your time zone is Beijing by default. I believe you must have seen the news broadcast! (Think again if you haven’t!) “Welcome to the newscast. It’s 19:00 Beijing time.” Take a look at the chart below to get an idea of all the time zones in the world

The earth is an approximate sphere, according to the circumference of 360° will be divided into 24 time zones, each time zone accounted for 15°, with the central longitude about 7.5° divided into a time zone. The prime meridian is used as the central meridian of the middle (zero) time zone, which is divided east-west in turn. For example, the dotted line in the middle of the boundary is the central meridian of the east zone.

It is worth noting that some countries actually span many time zones, for example, due to the size of our country! Across time zones 4, 5, 6, 7, 8 and 9 eastern, the situation is generally based on the time zone in which the national capital is located. For example, Xinjiang theoretically is the sixth east, but also unified use of the eighth East Beijing time!

But this may appear the situation is that you now look at the mobile phone is nine in the morning, Xinjiang friends look at the mobile phone is nine in the morning, but there may be xinjiang days haven’t bright……

UTC

Universal Time Coordinated (UTC) is also known as World Unified Time, World Standard Time, and international Coordinated Time. UTC is now the universal time standard, with all parts of the world agreeing to synchronize their time.

In simple terms, you can understand it as a norm, and all countries are willing to abide by this norm to keep time. All countries use the same norm, which makes it much easier to calculate time.

GMT

GMT (Greenwich Mean Time). It sets the time for the sun to pass through the Royal Greenwich Observatory on the outskirts of London, England, at 12 noon each day.

Greenwich Mean Time (GMT) was the world standard until 1972. GMT ceased to be a time standard after 1972.

In short, this is also a specification, but it was before 1972, after which almost all use UTC. In contrast, GMT and UTC are the same when accurate to the second, and if you want to be accurate to the second level or below, you need to use UTC.

A Unix timestamp

This is based on the total number of seconds/milliseconds since UTC 1970.01.01 00:00:00, so the total number of seconds/milliseconds is the same all over the world. This means that Unix timestamps are not timezone dependent. You can verify this by executing the following Java code on two servers in different time zones.

System.currentTimeMills();
Copy the code

If you don’t have a foreign server, you can use Docker to run two containers, specifying different time zones in the environment variable.

Local time

The time used in everyday life is often called local time. This time is equal to the local time in our (or used) time zone, defined by an offset from Universal Standard Time (UTC-0). This offset can be expressed as UTC- or UTC+, followed by the offset hour. Each time zone to the east is +1 hour, and each time zone to the west is -1 hour. For example, the offset of Beijing time from UTC-0 in China is UTC+8.

Note that in PostgreSQL, UTC+ and – are the opposite, and UTC-8 represents plus eight hours relative to UTC, and minus eight hours relative to UTC……

conclusion

I’m sure many of my friends, like me, have never worked on a multinational project before and may have paid little attention to the outdated areas. This article clears up the basics of time zones, and the next one will introduce you to the new generation of Java8 time apis.

Please like and follow this article if it’s been helpful to you. Your support is my motivation to continue to create!