CentOS 8系統更改時鐘時區

對於許多與系統相關的任務和進程,使用正確的時區是必不可少的。例如,cron守護進程使用系統的時區執行cron做業,日誌文件中的時間戳基於同一系統的時區。

環境linux

Centos8centos

檢查如今的時區ide

timedatectl是一個命令行實用程序,容許您查看和更改系統的時間和日期。spa

[root@localhost ~]# timedatectl 
               Local time: Tue 2020-03-31 16:35:23 CST
           Universal time: Tue 2020-03-31 08:35:23 UTC
                 RTC time: Tue 2020-03-31 08:35:23
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Centos8如何更改時區Centos8如何更改時區

更改時區3d

在更改時區以前,您須要找出要使用的時區名稱。要列出全部可用時區,請使用下面的命令日誌

[root@localhost ~]# timedatectl list-timezones
…
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
…

而後使用set-timezone選項更改時區,好比更改成Europe/Berlin:orm

[root@localhost ~]# timedatectl set-timezone Europe/Berlin

Centos8如何更改時區Centos8如何更改時區

使用建立連接的方式更改時區blog

若是運行的是舊版本的Centos,好比Centos6以前的版本,而且系統上不存在timedatectl命令,則能夠經過將/etc/localtime符號連接到/usr/share/zoneinfo目錄中的時區文件來更改時區。進程

查看一下/usr/share/zoninfo下面的時區文件,get

[root@localhost ~]# ls /usr/share/zoneinfo/
[root@localhost ~]# ls /usr/share/zoneinfo/Asia/

Centos8如何更改時區Centos8如何更改時區

Centos8如何更改時區Centos8如何更改時區
如今替換時區文件。

[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@localhost ~]# date
Tue Mar 31 16:53:59 CST 2020

能夠看到已經切換到了CST中國標準時間

總結

在本文中,使用了兩種方式修改時區。一種是使用timedatectl,另外一種方式使用建立連接的方式。

相關文章
相關標籤/搜索