Linux修改设置时区的几种方法

方法一:

tzselect

在提示下进行时区选择,但是测试发现选择完成后并不生效,需要执行提示的命令:
TZ=‘Asia/Shanghai’; export TZ
并将此命令追加写入/etc/profile,否则重启会失效。

echo " TZ='Asia/Shanghai'; export TZ  ">>/etc/profile

在这里插入图片描述在这里插入图片描述
方法二:

复制相应的时区文件,替换系统时区文件;或者创建链接文件

rm -rf /etc/localtime
//先删除/etc/localtime,否则若存在此文件软链接会失败
cp /usr/share/zoneinfo/主时区/次时区 /etc/localtime
//或者
ln -s /usr/share/zoneinfo/主时区/次时区 /etc/localtime

例如:在设置中国时区使用亚洲/上海(+8)

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
//或者
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

方法三:

timedatectl -h
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai

方法三比较简单,优先推荐,另外注意除了方法一可以立即生效,其他两种方法,登陆用户需要注销当前会话后生效

参考文档:
https://jingyan.baidu.com/article/fa4125acb7328628ac70920e.html
https://blog.csdn.net/gezilan/article/details/79422864
https://blog.csdn.net/zsg88/article/details/75212835

猜你喜欢

转载自blog.csdn.net/szuwangjl/article/details/86603762