美文网首页
ubuntu设置timezone

ubuntu设置timezone

作者: ShootHzj | 来源:发表于2023-01-09 12:11 被阅读0次

备注: timedatectl 命令是systemd的一部分,需要您的linux服务是由systemd拉起才能使用,由其他init进程启动的,如容器内,不能使用这个命令。

查看当前时区

可以通过date +%Z命令来查看当前的时区

~$ date +%Z
CST

timedatectl命令可以看到更详细的信息

~$ timedatectl
               Local time: Mon 2023-01-09 12:05:26 CST
           Universal time: Mon 2023-01-09 04:05:26 UTC
                 RTC time: Mon 2023-01-09 04:05:27
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

查询可设置的时区

通过timedatectl list-timezones 来查看

~$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
...skipping...
US/Hawaii
US/Indiana-Starke
US/Michigan
US/Mountain
US/Pacific
US/Samoa
UTC
Universal
W-SU
WET
Zulu

设置时序

VM

通过bash命令

# you can modify UTC to other timezone you desired
export TZ=UTC
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

通过timedatectl命令

timedatectl set-timezone UTC

dockerfile

# you can modify UTC to other timezone you desired
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

相关文章

网友评论

      本文标题:ubuntu设置timezone

      本文链接:https://www.haomeiwen.com/subject/yvducdtx.html