Get the App
SLTechnology News&Howtos  ›  Development  › 

How to change the time zone under Linux

Shulou Source: shulou.com Published: 2022-06-01 16:02:11 09月12日 Update

This article will explain in detail how to change the time zone under Linux, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

Using the correct time zone is essential for many system-related tasks and processes. For example, cron daemons use the system time zone to perform cron tasks, and timestamps in log files are also based on the system time zone.

Check the current time zone

Timedatetl is a command-line utility that allows you to view and change the time and date of your system.

[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

change the time zone

Before you can change the time zone, you need to find out the name of the time zone you want to use. To list all available time zones, use the following command:

[root@localhost ~]# timedatectl list-timezones…Asia/SamarkandAsia/SeoulAsia/ShanghaiAsia/SingaporeAsia/Srednekolymsk…

Then use the set-timezone option to change the time zone, for example to Europe/Berlin:

[root@localhost ~]# timedatectl set-timezone Europe/Berlin

Change the time zone using the way links are created

If you are running an older version of Centos, such as a version prior to Centos6, and the timedatetl command does not exist on your system, you can change the time zone by linking the/etc/localtime symbol to the time zone file in the/usr/share/zoneinfo directory.

Check out the time zone file under/usr/share/zoninfo,

[root@localhost ~]# ls /usr/share/zoneinfo/[root@localhost ~]# ls /usr/share/zoneinfo/Asia/

Now replace the time zone file.

[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime[root@localhost ~]# dateTue Mar 31 16:53:59 CST 2020

You can see that it has switched to CST China Standard Time.

About "how to change the time zone under Linux" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Time zone system file command article utility task time more version program link face-to-face good necessary content can be passed name article method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Shulou Technology Xiaomi Microsoft