这篇文章将为大家详细讲解有关Linux下如何更改时区,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
使用正确的时区对于很多系统相关的任务和进程都是基本的必要的。例如:cron 守护程序使用系统时区来执行 cron 任务,并且日志文件中的时间戳也是基于系统时区的。

检查现在的时区
timedatectl是一个命令行实用程序,允许您查看和更改系统的时间和日期。
[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

更改时区
在更改时区之前,您需要找出要使用的时区名称。要列出所有可用时区,请使用下面的命令:
[root@localhost ~]# timedatectl list-timezones…
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
…
然后使用set-timezone选项更改时区,比如更改为Europe/Berlin:
[root@localhost ~]# timedatectl set-timezone Europe/Berlin

使用创建链接的方式更改时区
如果运行的是旧版本的Centos,比如Centos6之前的版本,并且系统上不存在timedatectl命令,则可以通过将/etc/localtime符号链接到/usr/share/zoneinfo目录中的时区文件来更改时区。
查看一下/usr/share/zoninfo下面的时区文件,
[root@localhost ~]# ls /usr/share/zoneinfo/[root@localhost ~]# ls /usr/share/zoneinfo/Asia/

现在替换时区文件。
[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime[root@localhost ~]# dateTue Mar 31 16:53:59 CST 2020
可以看到已经切换到了CST中国标准时间
关于“Linux下如何更改时区”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。