How to change linux time zone

WBOY
WBOYOriginal
2022-01-27 15:13:0951069browse

Method: 1. Use "sudo rm -f /etc/localtime" and other commands to modify the system time zone; 2. Use Systemd to change the Linux system time zone. The syntax is "sudo timedatectl set-timezone 'time zone'".

How to change linux time zone

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to modify the Linux time zone

If your Linux system time zone configuration is incorrect, you must manually adjust it to the correct local time zone. NTP's time synchronization process only calculates the offset between local time and UTC time, so configuring an NTP to synchronize time does not solve the problem of incorrect time zones. Therefore, when using foreign cloud computing service providers such as Microsoft Azure or other VPS or virtual machines, you need to pay attention to whether they are consistent with the time zone of mainland China.

View the current time zone of Linux

You can use the following command to easily check the current time zone of the Linux system:

date
ls -l /etc/localtime

How to change linux time zone

Get Time zone TZ value

To change the Linux system time zone, you must first know the TZ value of your local time zone. Use the tzselect command to view and select the installed time zone file.

Execute the tzselect command

How to change linux time zone

Select your continent, country and city through the wizard

tzselect will eventually be formatted in Posix TZ format (such as Asia /Shanghai) output the value of your time zone and record this.

How to change linux time zone

Change the time zone for each user

Linux users A multi-user system, each user can configure what they need Time zone, you can add a TZ environment variable for yourself:

export TZ='Asia/Shanghai'

After the execution is completed, you need to log in to the system again or refresh ~/.bashrc to take effect.

source ~/.bashrc

Change the Linux system time zone

To change the system-wide time zone of the Linux system, you can use the following command:

sudo rm -f /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Note: /usr/share Please replace the specific time zone in /zoneinfo/Asia/Shanghai with the TZ value you obtained.

Use Systemd to change the Linux system time zone

If the Linux system you are using uses Systemd, you can also use the timedatectl command to change the Linux system-wide time zone. There is a system service named systemd-timedated under Systemd that is responsible for adjusting the system clock and time zone. We can use the timedatectl command to configure this system service.

sudo timedatectl set-timezone 'Asia/Shanghai'

How to change linux time zone

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to change linux time zone. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn