1. UTC時區切換到CST 時區
# echo "export TZ='Asia/Shanghai'" >> /etc/profile
# cat /etc/profile |grep TZ
# source /etc/profile
# date -R
# date
Sat Aug 19 17:03:17 CST 2017
2.修改時區
時區設置用tzselect 命令來實現。但是通過tzselect命令設置TZ這個環境變量來選擇的時區,需要將變量添加到.profile文件中。(/etc/profile)
一、tzselect命令執行
執行tzselect命令 --> 選擇Asia --> 選擇China --> 選擇east China - Beijing, Guangdong, Shanghai, etc-->然后輸入1。
執行完tzselect命令選擇時區后,時區並沒有更改,只是在命令最后提示你可以執行 TZ=’Asia/Shanghai’; export TZ 並將這行命令添加到.profile中,然后退出並重新登錄。
二、修改配置文件來修改時區
[root@linux-node ~]# echo "ZONE=Asia/Shanghai" >> /etc/sysconfig/clock
[root@linux-node ~]# rm -f /etc/localtime
#鏈接到上海時區文件
[root@linux-node ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
執行完上述過程后,重啟機器,即可看到時區已經更改。
備注:
在centos7中設置時區的命令可以通過 timedatectl 命令來實現
[root@linux-node ~]# timedatectl set-timezone Asia/Shanghai
相關鏈接:
https://www.cnblogs.com/ibnode/p/3573302.html