安卓系统

如何在Linux中设置或更改时区

2分钟修改 Kali Linux 时间 (为了科学上网)

2分钟修改 Kali Linux 时间 (为了科学上网)

目录:

Anonim

时区是具有相同标准时间的地理区域。 通常,时区是在操作系统的安装过程中设置的,但以后可以轻松更改。

对于许多与系统相关的任务和过程,使用正确的时区至关重要。 例如,cron守护程序使用系统的时区执行cron作业。 时区也用于日志时间戳。

本教程介绍了在Linux中设置或更改时区的必要步骤。

检查当前时区

timedatectl 是一个命令行实用程序,可让您查看和更改系统的时间和日期。 它在所有基于systemd的现代Linux系统上都可用。

要查看当前时区,请在不使用任何选项或参数的情况下调用 timedatectl 命令:

timedatectl

Local time: Tue 2019-12-03 16:30:44 UTC Universal time: Tue 2019-12-03 16:30:44 UTC RTC time: Tue 2019-12-03 16:30:44 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: no systemd-timesyncd.service active: yes RTC in local TZ: no

上面的输出显示系统的时区设置为UTC。

通过将 /etc/localtime 文件符号链接到 /usr/share/zoneinfo 目录中的二进制时区标识符来配置系统时区。

检查时区的另一种方法是使用 ls 命令查看symlink指向的路径:

ls -l /etc/localtime

lrwxrwxrwx 1 root root 27 Dec 3 16:29 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

在Linux中更改时区

在更改时区之前,您需要找出要使用的时区的长名称。 时区命名约定通常使用“地区/城市”格式。

要查看所有可用时区,请使用 timedatectl 命令或在 /usr/share/zoneinfo 目录中列出文件:

timedatectl list-timezones

… America/Montserrat America/Nassau America/New_York America/Nipigon America/Nome America/Noronha…

一旦确定了哪个时区适合您的位置,请以root或sudo用户身份运行以下命令:

sudo timedatectl set-timezone

例如,要将系统的时区更改为 America/New_York 请输入:

sudo timedatectl set-timezone America/New_York

要验证更改,请再次调用 timedatectl 命令:

timedatectl

Local time: Tue 2019-12-03 13:55:09 EST Universal time: Tue 2019-12-03 18:55:09 UTC RTC time: Tue 2019-12-03 18:02:16 Time zone: America/New_York (EST, -0500) System clock synchronized: no systemd-timesyncd.service active: yes RTC in local TZ: no

任务完成! 您已经成功更改了系统的时区。

通过创建符号链接来更改时区

删除当前的符号链接或文件:

sudo rm -rf /etc/localtime

确定要配置的时区并创建符号链接:

sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

通过列出 /etc/localtime 文件或调用 date 命令来验证它:

date

输出包括时区,在此示例中为“ EST”。

Tue Dec 3 14:10:54 EST 2019

结论

要在Linux系统中更改时区,请使用 sudo timedatectl set-timezone 命令,后跟要 sudo timedatectl set-timezone 的长名称。

如有任何疑问,请随时发表评论。

终奌站