Ubuntu设置时区

一 查看当前时区

root@node01:~# timedatectl 
               Local time: Wed 2021-11-03 08:43:55 UTC
           Universal time: Wed 2021-11-03 08:43:55 UTC
                 RTC time: Wed 2021-11-03 08:43:55    
                Time zone: Etc/UTC (UTC, +0000)       
System clock synchronized: yes                        
              NTP service: active                     
          RTC in local TZ: no    

二 选择时区

# 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          14) Hong Kong            27) Laos              40) Saudi Arabia
 2) Antarctica          15) India            28) Lebanon              41) Singapore
 3) Armenia          16) Indonesia            29) Macau              42) Sri Lanka
 4) Azerbaijan          17) Iran            30) Malaysia          43) Syria
 5) Bahrain          18) Iraq            31) Mongolia          44) Taiwan
 6) Bangladesh          19) Israel            32) Myanmar (Burma)          45) Tajikistan
 7) Bhutan          20) Japan            33) Nepal              46) Thailand
 8) Brunei          21) Jordan            34) Oman              47) Turkmenistan
 9) Cambodia          22) Kazakhstan        35) Pakistan          48) United Arab Emirates
10) China          23) Korea (North)        36) Palestine          49) Uzbekistan
11) Cyprus          24) Korea (South)        37) Philippines          50) Vietnam
12) East Timor          25) Kuwait            38) Qatar              51) Yemen
13) Georgia          26) Kyrgyzstan        39) Russia
#? 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:    Wed Nov  3 16:45:29 CST 2021.
Universal Time is now:    Wed Nov  3 08:45:29 UTC 2021.
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

三 创建软连接

root@node01:~# ln -svf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
'/etc/localtime' -> '/usr/share/zoneinfo/Asia/Shanghai'

四 验证当前时区

root@node01:~# timedatectl 
               Local time: Wed 2021-11-03 16:49:50 CST
           Universal time: Wed 2021-11-03 08:49:50 UTC
                 RTC time: Wed 2021-11-03 08:49:50    
                Time zone: Asia/Shanghai (CST, +0800) 
System clock synchronized: yes                        
              NTP service: active                     
          RTC in local TZ: no      

五 修改时间为24小时制

root@node01:~# echo "LC_TIME=en_DK.UTF-8" >>  /etc/default/locale 

六 验证时间格式

root@node01:~# reboot
root@node01:~# date
Wed Nov  3 17:15:30 CST 2021

timedatectl

# timedatectl set-timezone Asia/Shanghai
posted @ 2021-11-03 16:51  小吉猫  阅读(2315)  评论(0编辑  收藏  举报