如何在Debian 10上设置或更改时区
原文地址:如何在Debian 10上设置或更改时区
对于许多与系统相关的任务和过程,使用正确的时区至关重要。例如,cron守护程序使用系统的时区执行cron作业,而日志文件中的时间戳基于同一系统的时区。本文介绍了如何在Debian 10 Linux上设置或更改时区。
在Debian上,系统的时区是在安装过程中设置的,但以后可以轻松更改。
检查当前时区
timedatectl
是一个命令行实用程序,可让您查看和更改系统的时间和日期。它在所有基于systemd的现代Linux系统上都可用:
timedatectl
以下输出显示系统的时区设置为“ UTC”:
Local time: Fri 2020-04-03 19:23:29 UTC
Universal time: Fri 2020-04-03 19:23:29 UTC
RTC time: Fri 2020-04-03 19:23:29
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
通过符号链接/etc/localtime
到/usr/share/zoneinfo
目录中的二进制时区标识符来配置系统时区。您还可以使用以下ls
命令通过检查符号链接指向的路径来找到时区:
ls -l /etc/localtime
lrwxrwxrwx 1 root root 23 Nov 21 23:44 /etc/localtime -> /usr/share/zoneinfo/UTC
在Debian中更改时区
在更改时区之前,您需要找出要使用的时区的长名称。时区使用“地区/城市”格式。
要列出所有可用时区,可以列出目录中的文件,也可以使用以下选项/usr/share/zoneinfo
调用timedatectl
命令list-timezones
:
timedatectl list-timezones
...
America/Monterrey
America/Montevideo
America/Montserrat
America/Nassau
America/New_York
...
确定哪个时区适合您的位置后,以root或具有sudo特权的用户身份运行以下命令:
sudo timedatectl set-timezone your_time_zone
例如,要将系统的时区更改为America/Monterrey
,可以运行:
sudo timedatectl set-timezone America/Monterrey
通过使用以下timedatectl
命令检查当前系统的时区来验证更改:
timedatectl
Local time: Fri 2020-04-03 13:30:30 CST
Universal time: Fri 2020-04-03 19:30:30 UTC
RTC time: Fri 2020-04-03 19:30:30
Time zone: America/Monterrey (CST, -0600)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
通过创建符号链接来更改时区
如果您运行的是Debian的旧版本,并且timedatectl
系统上没有该命令,则可以通过将/etc/localtime
文件符号链接到目录中的时区二进制文件来更改时区/usr/share/zoneinfo
。
确定要配置的时区,并创建一个符号链接:
sudo ln -sf /usr/share/zoneinfo/America/Monterrey /etc/localtime
通过列出/etc/localtime
文件或发出timedatectl
or date
命令来验证更改:
date
Fri 03 Apr 2020 01:34:27 PM CST
结论
要更改Debian系统的时区,请运行sudo timedatectl set-timezone
命令,然后输入要设置的时区的长名称。
如有任何疑问,请随时发表评论。
{{ nComment.author.nickname }}
{{ nComment.time }}