UTC time & local time

Source: Internet
Author: User
Tags time zones

UTC time & local time (1)

The whole earth is divided into twenty-four time zones, each of which has its own local time. For international radio communication, a unified time is used for the sake of unification, called Universal coordination Time (UTC, Universal Time Coordinated ). The UTC time is the same as the Greenwich Mean Time (GMT, Greenwich Mean Time. In this article, UTC and GMT have the same meaning.

The Beijing Time Zone is GMT + 8, which is eight hours ahead of UTC. The Date Field in the email header is recorded as + 0800. If there is such a line in the email header:

Date: Thurs, 31 Dec 2009 09:42:22 + 0800

It indicates that the mail is sent at 09:42 (22 seconds) on Thursday, April 9, December 31. The local time of the mail is eight hours ahead of UTC (+ 0800, that is, UTC time ). The Date Field of the email header uses the 24-hour clock instead of the AM and PM to mark the previous afternoon.

Take the email sending time as an example. If you want to convert this time to UTC, you can use the following formula:

UTC + time zone Difference = local time

The Time Zone difference is positive in the east and negative in the West. Here, the UTC + 8 Zone Time Zone difference is recorded as + 0800,

UTC + (+ 0800) = Local (Beijing) time (1 type)

UTC = local time (Beijing Time)-0800 (Type 2)

0942-0800 = 0142

That is, the UTC time is 01:42:22 that day. If the result is a negative number, it means the day before UTC. Adding the negative number to 2400 is the time of the day before UTC. For example, if the local (Beijing) Time is 0432 (04:32 in the morning), the UTC time is 0432-0800 =-0368, and the negative number means the previous day,-0368 + 2400 = 2032, 08:32 the previous day.

The Time Zone of New York is the West five zone, which is five hours behind UTC and recorded as-0500:

UTC + (-0500) = New York time (3)

UTC = New York time + 0500 (4)

Compare (2) with (4,

UTC = Beijing Time-0800 = New York time + 0500 (type 5)

That is, Beijing time = New York time + 1300 (6)

That is, Beijing time is 13 hours ahead of New York time, in the format of (6,

New York time = Beijing Time-1300 (7)

In late April, when New York switched to daylight saving, it became an hour earlier than the standard time in New York. It became the standard time in the West 4 region and became-0400.

When UTC + (-0400) = New York Region, apply the above formula,

Beijing time = Daylight Saving Time in New York + 1200

Daylight Saving Time in New York = Beijing Time-1200

Among these conversions, the most important formula is

UTC + time zone Difference = local time

The Time Zone difference is positive in the east and negative in the West. For example, the UTC + 8 (Beijing) region is + 0800, the west Five (New York) region is-0500, the California region is West eight, the-0800, the central United States time zone is west six, and the-0600, the US Mountain Time Zone is the west seven zone,-0700, the Pacific time zone is the West eight zone,-0800, and uses the Daylight Time System in summer to become-0700. The German time zone is located in the East 1 region, with a value of + 0100 and a value of + 0200 in summer.

Most email programs, such as Outlook Express, convert the time into local time before displaying the time. For example, the Date Field of the email is:

Date: Fri, 08 Nov 2002 09:42:22 + 0800

Outlook Express is displayed as follows:

Date: Thur, 07 Nov 2002 08:42:22, converted Beijing time into New York time, and converted the 24-hour format into 12-hour format. Of course, in order to convert the time correctly, both the sender and receiver's computer must set the correct time zone. Here, the sender's time zone must be set to the UTC + 8 Beijing time zone, and set my time zone to the west Five.

 

UTC time & local time (2)

First, let's take a look at the concepts of time and the differences between them. The time concepts that need to be understood include:
Local time)
Greenwich Mean Time GMT)
Universal Time Coordinated UTC)
Local time, obviously no need to explain

First, let's look at the time standard:
(1) World Time
Universal Time is the earliest time standard. In 1884, 1 s was set internationally to 1/8. 64 × 104 of the average daily length for the year. The time system formed by this standard is called the world, that is, ut1. In 1972, the international atomic time mark was used internationally. Since then, the time passed by the Greenwich Mean Observatory's primary meridian has been called the Universal Time, namely ut2, or Greenwich Mean Time (GMT ), it is the universal time after the periodic difference of the Earth's rotation speed is corrected.
(2) Atomic hour
In 1967, people developed a high-precision Atomic Clock Based on the characteristics of the extremely regular atomic oscillation cycle, and set the time experienced by 9192631770 weeks of Atomic Energy Transition Radiation to 1 s. The time used now is the international atomic time defined in October 1971. It is a unified atomic time that is obtained after being compared by more than 200 atomic clocks in the world and then processed by the time of the International Weighing and balance Bureau, tai for short.
(3) World coordination
World coordination is based on the rotation of the Earth. Since the Earth's rotation speed is uneven, not every day is accurate 86400 atomic s, resulting in a 1 s error between the rotation time and the world. To correct this error, the International Institute of Earth Rotation adjusted the Greenwich Mean Time by s based on the actual condition of the Earth's rotation, and released the standard time to the world jointly with the time of the International Bureau of Weights and Measures, this is the so-called world coordination Time (UTC: coordinatde Universal Time ). The format of UTC is as follows: Year (Y), month (M), Day (D), hour (H), minute (min), and second (s.

There are two time differences in the GPS system: one is UTC, the other is LT (local time), the difference is that the time zone is different, UTC is the time zone 0, local time is the local time, for example, if Beijing is (UTC + 8), UTC is, and UTC is eight hours later than Beijing.
Through the above understanding, we can think that Greenwich Mean Time is the Time Coordinated Time (GMT = UTC), Greenwich Mean Time and UTC time are calculated in seconds.

In our daily work, most of the time written in computer logs is calculated using UTC time. How can we convert UTC time to local time for viewing logs, how can I convert the local time into UTC time during program development?
The following describes a simple tool used to convert the local time and local time using the date command of Linux/Unix.
As we all know, the UTC time displayed on the computer is calculated in seconds starting from (0:00:00, January 1, January 01, 1970. The UTC time that we see is the total number of seconds from the time point of January 1, 1970 to the specific time.

Take my fc9 platform as an example:

1. Use the date command to obtain the local time
Mon Jan 5 21:06:48 CST 2009

2. Convert the time that is easy to understand locally to UTC time. Use the date command to format the time in UTC.
Date + % s-d "Mon Jan 5 21:06:48 CST 2009"
The returned result is: 1231160808 # January 1, 1970 seconds from 0:00:00, January 1, 1231160808 to 21:06:48, this evening
1231160808 this is what we call UTC or Greenwich Mean Time.

3. Use the date command to convert the incomprehensible UTC time to the understandable local time

Here, we can modify the Greenwich Mean Time above to convert it, such as 1231130828.
Date-d "UTC 1231130828 sec"
The returned result is: Mon Jan 5 12:47:08 CST 2009 # It is 12:47:08 noon today.

4. Use the date command to format the local time
Date + % x-d "Mon Jan 5 12:47:08 CST 2009"
Returned results: 12: 47: 08 pm

Date + % x-d "Mon Jan 5 12:47:08 CST 2009"
The returned result is: 12:47:08

Date + '% x % W'-d "Mon Jan 5 12:47:08 CST 2009"
Return result: 01/05/2009 12:47:08 PM 01 # The following 01 is Monday. If it is % W, 1 is returned.

Date + '% Y-% m-% d % H: % m: % S % W'-d "Mon Jan 5 12:47:08 CST 2009"
The returned result is: 12:47:08

Format the UTC time:
Date + '% x % x'-d "1970-01-01 UTC 1231130828 sec"
Returned results: 12:47:08

The date command also has many formatting parameters, which are very powerful. You can use "man date" or "info date" for reference.

If a friend of Windows does not have a Linux environment, there is no way to convert the time. You can recommend a website to convert the time:
Http://kanlis.7ta.cn/time.html

 

5. Set the current time

Date-s 12:41:30

Whether the set time is UTC or CST depends on the system settings. You can view it in/etc/sysconfig/clock.

6. Set the current date

Data-s 12/31/09

The format is month, day, or year.

7. Set the system time zone

A. # timeconfig

After you type this command, select the required time zone as prompted; only for Redhat Linux and centos

B. # cp/usr/share/zoneinfo/UTC/etc/localtime

In this way, you can use the UTC time standard instead of the current time zone settings.

# Cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime

Replace the current time zone with the time zone of Shanghai, China.

# Cp/usr/share/zoneinfo/$ main Time Zone/$ Time Zone/etc/localtime

Copy the corresponding time zone file to replace the System Default Time Zone

C. # tzselect

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.