Time in Javascript

Source: Internet
Author: User
Tags gmt time zone time zones sunrise time
The time in Javascript will inevitably deal with time when programming. For example, to complete a second kill, it involves time access, time synchronization, time difference calculation, and many other details. A simple example of JavsScript. When we enter new Date () in the browser console, the following result is obtained:

Sun Oct 30 2016 16:27:04 GMT + 0800 (CST)

The meaning of the first half of the output is easy to understand. It represents the GMT, + October 30, 2016, and CST at Sunday, 0800, 16:27:04 P.M., and the second half. What exactly does CST mean, this article will show you more about the time in JS.

1. Time Representation

In ancient times, one of the most important tasks of astronomy was to measure time and develop calendars. In ancient China, one year was divided into December and Twenty-four Solar Terms, and one day was divided into twelve hours. The purpose was to provide a set of Efficient Time Representation Methods to guide farming. With the development of modern society, the expression of time also requires a set of more scientific and accurate methods.

Measurement

Start with timing tools

In ancient times, humans had to work and rest according to the changes of the Sun and the Earth. People were doing things on their own, and they continued to work and rest. At this time, people do not have any special concepts about time, and they do not need timing tools.

In the Chinese Zhou Dynasty, people divide a day into 12 hours: Child, ugly, Yin, Mao, Chen, Si, Wu, Wei, Shen, you, Wu, Hai, corresponding to midnight, Jiming, pingdan, sunrise, food time, Yuzhong, Japanese, evening, and people respectively. It is used to guide people's daily life patterns. At this time, we use the hourglass and the sun to record the approximate time. We can tell that the shortest time is 1 hour (2 h ).

Later, the Industrial Revolution brought mankind into the industrial age. At this time, people had a more refined division of time. One day was divided into 12 hours, 60 minutes per hour, 60 seconds per minute. In order to produce data more efficiently, we use watches and clocks to record the time, and our use of the time has reached the second level.

Now, our timing tool has been upgraded to a cold atomic clock. For example, China's Beidou Navigation Satellite System uses atomic clocks to record time, and its timing accuracy has reached the nanosecond level (1ns = 10 ^-9 s ). We have combined the space and time to calculate the space and convert the time in the space.

Ps: I once heard a speech by Xu Ying, director of the Chinese Emy of sciences, on Beidou in the park. I cannot help but convince the people of the creativity and strength of China.

With the advancement of human civilization, timing tools are also constantly evolving. With these tools, the division of time is getting finer and finer, and the utilization of time resources is getting higher and higher.

Time Unit

We use time units to express specific time intervals. Commonly Used time units include century, year, quarter, month, day, hour, minute, second, millisecond, subtle, and nanosecond. At present, the shortest time unit that humans can measure is attosecond, which is the lifetime of neutral π meson, equivalent to 10 ^-18 seconds.

It can be said that the subdivision process and standard setting process of people's time are actually the process of human exploration time and utilization of time. Our cognition of time units can reflect our cognition of our own time and space. The time unit also reflects the development history of human scientific civilization.

Time

We usually say that it is now nine o'clock, which actually refers to the moment. We want to express that the current time point has reached 9 o'clock. It has no size or direction. It only expresses a specific time point. For example, we use a ruler to measure the length. We also use a ruler that marks the second and the hour to measure the time. The moment is just a scale on a ruler that we can understand. The only difference is that the length of a space is always the same, and time is always increasing irreversible.

2. Time Standardization

First, we should realize that time is unified throughout the universe. From the birth of the universe to the present, we can always use a specific time interval value to represent the time we have experienced. It is a fixed value. So we can't help asking why we say that we are here at AM, while the UK is at AM. Isn't that two different times? This raises the question of time standards that we will discuss below.

In the past, the scope of human activities was relatively small, and we basically did not notice the impact of time zones on human work and rest. We can't imagine that when we work hard in the sun, people on the other side of the earth have been dreaming.

However, after the industrial revolution, human production and transportation continued to improve, and global cooperation became an unstoppable trend. At this time, people have realized that the Earth is constantly rotating from the west to the east, and the rotation of a week is one day. The sunrise time varies with regions with different longitude. For example, when China's Beijing is noon, New York on the other side of the ocean is just late at night. At a.m., we called and said that XXX in the United States should go to work. The other party must be a face-recognition (meng) middleware (bi). I am going to wash and sleep.

It is people who recognize the astronomical Law of the Earth's rotation that requires a set of globally unified time standards. In this way, we can calculate the local time (sunrise and sunset time) of any region of the earth based on the local time ), to facilitate better collaboration.

Greenwich Mean Time (GMT)

Greenwich Mean is the royal Greenwich Observatory on the outskirts of London. We often say that Greenwich mean a set of time metering systems based on the time of the land.

In order to accurately express the time of each region, the International longitude Conference decided to set the longitude line for calculating the longitude through the Greenwich mean astronomy heri centre, called the Meridian. It is regarded as a unified time standard for the calculation of the average sun period from the primary meridian to the east and the west, respectively. This is the origin of GMT time. It is a set of time standards defined by the rotation of the earth. It plays an important role in daily life, astronomical navigation, cosmic flight, and other human activities.

The formulation of GMT also produces the concept of time zone. When we listen to foreign news reports, we often hear what happened at XX o'clock, yy at local time, and then balabala. In fact, this is to avoid time differences between people in different time zones in terms of time representation.

Time Zone specifies the standard Time for a region. In theory, it is divided into a time zone by extending the longitude of 7.5 to the east and west at the center of the Meridian divided by 15. In fact, because of the irregular layout of each country, it usually spans multiple time zones. Therefore, the country also specifies an actual time zone within the entire administrative region, which is called the legal time zone. For example, China, from the West to the East, spans the east five, the east six, the east seven, the East eight and the East nine time zones. After the founding of the People's Republic of China, the country adopted the UTC time zone of the capital Beijing as the standard time, it is called Beijing time.

Coordinated Universal Time (UTC)

UTC is often mistaken for GMT. In fact, the representation of the two is completely different.

The origin of UTC

Humans observe a slow decline in the rotation of the earth. After a week, the rotation of the earth will take more than 24 hours. Therefore, the GMT time is no longer suitable for use as the standard time. The current standard time is the Coordinated Universal Time when the atomic clock is reported. This is a time scale maintained by the International metering Bureau and the International Earth Rotation Service (IERS, it is the benchmark for coordinated broadcasting of standard frequencies and time signals.

Why is it too messy to get a UTC time? In fact, no one wants to be so troublesome. This is what the earth is "turning.

We often think that the earth's rotation is 24 hours a week, and because the earth's rotation speed slows down, after 24 hours, the earth may not have been running for a week, to ensure that the 24 h time matches the complete week of the Earth, it is necessary to let the time on the clock wait for the earth to rotate for a week, which is the meaning of the word "coordination" in the coordinated world. The UTC Time is slower than the International Atomic Time (TAI.

Note: Second is the basic international unit of time. The International Standard 1 second is the duration of the 133 cycle of the radiation corresponding to the transition between two super-fine levels of the ground state of the zeu 9,192,631,770 atom.

To put it bluntly, the TAI time is defined based on the atomic law and will not change for a long time. UTC is the time set to conform to the cycle of the Earth's rotation. UTC will stop global clocks and make up the difference between the slow rotation of the earth, and the correction and synchronization mechanism is IERS. All countries around the world determine the local time based on the UTC time and the time zone of their respective countries, so as to ensure the low-error synchronization of global time.

Leap Second

UTC modifies the time by adding leap-secons to eliminate the effect of slow rotation on the earth. A leap second is specially set to balance the time difference between the rotation of the Earth and the atomic clock. If you do not add a leap second, it may take tens of thousands of years, and the noon will change to AM. Over a few millions of years, the winter on the calendar will change to summer, then the entire production and life will be messy.

The introduction of Leap seconds is the year of June and the end of December, depending on the difference in the evolution of the UTC-TAI, and every six months will announce whether to join the leap second (this is the IERS job ).

The last leap second was introduced at UTC 23: 59: 60. The next leap second was introduced:

23: 59: 592016-12-31 23: 59: 602017-01-01 00:00:00

The difference between 00:00:00 UTC and 00:00:00 UTC is: UTC-TAI =-36 s. That is to say, our UTC time standard is 36 seconds slower than the actual atomic clock time.

PS1: Do you feel like you have earned more than 36 s! PS2: most of the time currently used by humans is UTC time, but many times the GMT time zone division rules are retained, so the GMT time is displayed in many places.

Beijing Time (China Standard Time, CST)

Let's look at our country's time benchmark. Beijing time is not determined in Beijing, but is determined by the National Time Service Center of the Chinese Emy of Sciences (the National Time Service Station) located in the geometric center of the Chinese territory, linting, Shaanxi Province, and Pucheng, Shaanxi province) and the two Hydrogen Atom clock groups are achieved through Precision comparison and computation, and are compared and determined in real time by satellite and global time service departments. Domestic devices can synchronize with local Time through the NTP (Network Time Protocol) server provided by the National Time Service Center. For more information, see here.

On Mac, you can run the following command and the NTP server:

Region ~ Sudo ntpdate-u cn.pool.ntp.org
1 Nov 03:20:08 ntpdate [84376]: adjust time server 59.46.44.253 offset 0.014804 sec
Region ~

3. Summary

Back to the beginning of the article, we mentioned that when new Date () is output data, all the content is clear:

GMT, which indicates Greenwich Mean at ordinary times. However, GMT indicates that the time zone used is the GMT standard and the time zone uses the UTC time.

+ 0800 represents the time difference between the current time and the standard time, accurate to the minute. + 0800, indicating that the current time is earlier than UTC time 8 hours

CST refers to Beijing Time

Done!

4. Postscript

A programming language contains many details and often contains great wisdom. Taking the time mentioned in this article as an example, there are several simple words that contain the scientific and technological achievements of mankind over the past few hundred years and reflect the respect and reverence of mankind for time, each place deserves a refined taste.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.