How does the Linux system view the time zone where the settings are located? __linux

Source: Internet
Author: User
Tags local time

Reproduced from:
https://blog.csdn.net/huangjin0507/article/details/46368623

Second, how the Linux system to see the settings in the time zone.

Method 1: Use the date command to view the time zone

[Root@db-server ~]# Date-r

Sun, 2015 07:10:28-0800.

As shown in the RFC 2822 format, the above command outputs-0800 for the West VIII region, which is the time zone of San Francisco, and below represents the East eight region of our country (+0800)

[ROOT@LNX01 ~]# Date-r

Sun, 2015 23:06:02 +0800

Method 2: View the clock system configuration file

[Root@db-server ~]# More/etc/sysconfig/clock
Zone= "America/los_angeles"
Utc=true
Arc=false
As shown above, indicates that the time zone set by the system is "America/los_angeles", which is the West eight area.

How does the Linux system set up the time zone in which the system is located?

Method 1: There are many time zone files under/usr/share/zoneinfo/that can replicate these time zone files to overwrite/etc/localtime files:
[Root@db-server ~]# Date-r
Mon, 2015 10:42:26 +0800
[Root@db-server ~]# Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime
Cp:overwrite '/etc/localtime '? Y
[Root@db-server ~]# Date-r
Sun, 2015 18:42:49-0800.
[Root@db-server ~]#

Mode 2: Modify the time zone file for the link/etc/locatime:
[Root@db-server ~]# Ln/usr/share/zoneinfo/asia/shanghai/etc/localtime

Ln:creating hard Link/etc/localtime ' To/usr/share/zoneinfo/asia/shanghai ': File exists

[Root@db-server ~]# Rm/etc/localtime

Rm:remove regular file '/etc/localtime '? Y

[Root@db-server ~]# Ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime

[Root@db-server ~]# Date-r

Mon, 2015 10:56:10 +0800

Method 3: Use Tzselect to set the time zone

example, set the system time zone to East area eight (Beijing time)

[root@db-server ~]# tzselect
Please identify a location so this time zone the rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Austra Lia
8) Europe
9) Indian Ocean
Ten) Pacific Ocean
One) none-i want to specify the time zone using the P Osix TZ format. ? 5

Please select a country.
1) Afghanistan Israel) Palestine
2) Armenia) Philippines
3) Azerbaijan) Q ATAR
4) Bahrain) Kazakhstan Russia
5 Bangladesh) Korea (north)-Saudi Arabia
6) Bhutan) Ko Rea (South) Singapore
7) Brunei Kuwait) Sri Lanka
8) Cambodia Kyrgyzstan) Syria
9) (a) Laos) Taiwan (Cyprus) Lebanon) Tajikistan
(Timor) Macau
) Thailand Malaysia) Turkmenistan
Kong) Mongolia United Arab
-Emirates (India) (a) Uzbekistan
) Indonesia) Nepal Vietnam
Iran) Oman Yemen) Iraq (MB) (PDF) ng>? 9

Please select one of the following time zone regions.
1 East China-beijing, Guangdong, Shanghai, etc.
2) Heilongjiang (except Mohe), Jilin
3) China-sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) Most of Tibet & Xinjiang
5 West Tibet & Xinjiang 1

The following information has been given:

    East
    China-beijing, Guangdong, Shanghai, etc.

Therefore tz= ' Asia/shanghai ' would be used.
The local time is Now:sun a 23:31:51 CST 2015.
Universal Time is Now:sun 15:31:51 UTC 2015.
is the above information OK?
1) Yes
2) No Yes

Please enter 1 for Yes, or 2 for No. ? 1

You can make this change permanent for yourself by appending
tz= ' Asia/shanghai '; Export TZ
To the file '. Profiles ' in your home directory; Then log out and log in again.

Here's that TZ value again, this time on standard output so
can use The/usr/bin/tzselect command in shell scripts:
Asia/shanghai
Note: The Tzselect command only tells you what time zone is selected and does not take effect. So now it's not East 8 Beijing time. You can set the correct TZ environment variables and export them in. Profile,. Bash_profile, or/etc/profile. For example, in. Bash_profile set tz= ' Asia/shanghai '; Export TZ and make it effective.

[Root@db-server ~]# Source Bash_profile

[Root@db-server ~]# Date

Sun 23:37:40 CST 2015

[root@db-server ~]# date-r
Mon, a +0800-up 2015 10:42:26
[root@db-server ~]# cp/usr/share/zoneinfo/americ A/los_angeles/etc/localtime
Cp:overwrite/etc/localtime ' y
[root@db-server ~]# date-r
Sun, 2015 18:42:49-0800
[Root@db-server ~]#
[root@db-server ~]# date-r
Mon, out of 2015 10:42:26 +0800
[root@d B-server ~]# cp/usr/share/zoneinfo/america/los_angeles/etc/localtime
cp:overwrite/etc/localtime ' y
[ Root@db-server ~]# date-r
Sun, 2015 18:42:49-0800
[root@db-server ~]#

Related Article

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.