How to adjust Linux to the correct time zone

Source: Internet
Author: User

How to adjust Linux to the correct time zone

If your Linux system has incorrect time zone configuration, you must manually adjust it to the correct local time zone. NTP only calculates the offset between the local time and UTC time. Therefore, configuring an NTP to synchronize the time does not solve the problem of incorrect time zone. Therefore, when using foreign cloud computing service providers such as Microsoft Azure or other VPS and virtual machines, you must be aware of whether the time zone is consistent with that in mainland China.

View the current Linux time zone

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

datels -l /etc/localtime

Get the TZ value of the time zone

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

1. Execute the tzselect command

2. Select your continent, country, and city through the Wizard. tzselect will output your time zone value in Posix TZ format (for example, Asia/Shanghai) and record it.

Change the time zone of each user

Linux users have a multi-user system, and each user can configure their own time zone. You can add a new TZ environment variable for yourself:

export TZ='Asia/Shanghai'

After the execution is complete, you need to log on to the system again or refresh ~ /. Bashrc takes effect.

source ~/.bashrc
Change Linux time zone

To change the time zone of the entire Linux system, run the following command:

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

Note: Replace the actual time zone in/usr/share/zoneinfo/Asia/Shanghai with the obtained TZ value.

Use Systemd to change the Linux System Time Zone

If your Linux system uses Systemd, you can also use the timedatectl command to change the time zone of the Linux system. In Systemd, a system service named systemd-timedated 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'

Finally, if you find that the time between Ubuntu and Windows is not synchronized, refer to our previous articles and solutions.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.