当前位置:硬件测评 > LINUX 时间 /时区

LINUX 时间 /时区

  • 发布:2023-09-19 14:29

LINUX 时间 /时区

一、设置linux修改时区
首先查看当前时区

#date -R

显示结果为:
[root@localhost 20190528]# date -R

Wed, 29 May 2019 19:56:23 +0100
很显然不是东八区的时间。

方案一:使用tzselect命令实现
1、若不是,准备修改时区

#tzselect


2、查看是不是更改为东八区

[root@localhost 20190528]# date -R

Wed, 29 May 2019 19:57:14 +0100
结果非预期所期望的那样……怎么回事???

3、经排查,第一步中选了yes之后,有下面一段话。

此时时间并没有修改,需要执行TZ=‘Asia/Shanghai’; export TZ,并将这条命令写入.bash_profile文件。

4、执行命令TZ=‘Asia/Shanghai’; export TZ;

#TZ='Asia/Shanghai'; export TZ

5、再次查看是不是更改为东八区,显示成功

[root@localhost 20190528]# date -R
Wed, 29 May 2019 22:59:13 +0400

方案二:使用timedatectl命令
比较新的linux发行版(笔者尝试过ubuntu 16.04和centos7)均支持一个方便的命令timedatectl

1、使用timedatectl命令,查看当前的时区


[root@localhost ~]# timedatectl status 
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.Local time:2019-05-29 19:17:22 UTCUniversal time:2019-05-29 19:17:22 UTCRTC time:2019-05-29 19:17:22Time zone: n/a (UTC, +0000)NTP enabled: yes
NTP synchronized: noRTC in local TZ: noDST active: n/a

2、使用timedatectl命令,设置时区为东八区


# timedatectl list-timezones  | grep "Asia/S"
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
# timedatectl set-timezone "Asia/Shanghai"

3、查看当前的时区状态


# timedatectl status 
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.Local time:2019-05-29 23:23:59 SCTUniversal time:2019-05-29 19:23:59 UTCRTC time:2019-05-29 19:23:59Time zone: Asia/Shanghai (SCT, +0400)NTP enabled: yes
NTP synchronized: noRTC in local TZ: no

相关文章

最新资讯