ubuntu 18.04 lts 更新时区

最近有个需求要更新ubuntu服务器的时区,通过查找以后方法记录如下

系统环境

ubuntu 18.04

操作方法

➜  /etc tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
 1) Africa
 2) Americas
 3) Antarctica
 4) Asia
 5) Atlantic Ocean
 6) Australia
 7) Europe
 8) Indian Ocean
 9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the timezone using the Posix TZ format.
#? 4
Please select a country whose clocks agree with yours.
 1) Afghanistan              15) French S. Terr.          29) Kyrgyzstan               43) Russia
 2) Antarctica               16) Georgia                  30) Laos                     44) Saudi Arabia
 3) Armenia                  17) Hong Kong                31) Lebanon                  45) Seychelles
 4) Azerbaijan               18) India                    32) Macau                    46) Singapore
 5) Bahrain                  19) Indonesia                33) Malaysia                 47) Sri Lanka
 6) Bangladesh               20) Iran                     34) Mongolia                 48) Syria
 7) Bhutan                   21) Iraq                     35) Myanmar (Burma)          49) Taiwan
 8) Brunei                   22) Israel                   36) Nepal                    50) Tajikistan
 9) Cambodia                 23) Japan                    37) Oman                     51) Thailand
10) China                    24) Jordan                   38) Pakistan                 52) Turkmenistan
11) Christmas Island         25) Kazakhstan               39) Palestine                53) United Arab Emirates
12) Cocos (Keeling) Islands  26) Korea (North)            40) Philippines              54) Uzbekistan
13) Cyprus                   27) Korea (South)            41) Qatar                    55) Vietnam
14) East Timor               28) Kuwait                   42) Réunion                  56) Yemen
#? 10
Please select one of the following timezones.
1) Beijing Time
2) Xinjiang Time
#? 1

The following information has been given:

        China
        Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now:   Sat Dec  7 17:16:18 CST 2024.
Universal Time is now:  Sat Dec  7 09:16:18 UTC 2024.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
        TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

选择Asia
再选择china
再选择 北京
再选择yes 结束

这个工具只是一个格式提醒的工具,告诉你格式怎么写
还需要去
.profile、.bash_profile或者/etc/profile中设置正确的TZ环境变量并导出。

例如在.bash_profile里面设置 TZ='Asia/Shanghai'; export TZ并使其生效。

有点脱裤放屁的感觉。只是让配置更灵活了,让不同的用户可以有自己的时区去设置

一次性生效的参考这个文章,不限于debian、ubuntu、centos
https://ezlost.com/2019/04/12/centos7-%e5%8f%8a%e5%85%b6%e4%bb%96centos%e7%b3%bb%e7%bb%9f%e8%ae%be%e7%bd%ae%e6%97%b6%e5%8c%ba/

上一篇
下一篇