Title: Two ways to change the system time zone on Ubuntu
Correct time zone setting is very important to ensure accurate time and date in Ubuntu system. In this article, we will introduce two common methods to modify the time zone setting of an Ubuntu system: using timedatectl
commands and directly editing /etc/timezone
files. Let's take a look at the specific steps of these two methods.
Method 1: Use timedatectl
the command
-
open terminal
-
Run the command: Enter the following command in a terminal to get the current time zone setting:
timedatectl
-
List Available Time Zones: The command
timedatectl
will display the current time zone setting along with other relevant information. Take note of the ID of the time zone you want to change. -
Modify time zone: Enter the following command to change the time zone, replacing "YOUR_TIMEZONE" with the time zone ID you want to set:
sudo timedatectl set-timezone YOUR_TIMEZONE
For example, if you want to set the timezone to "Asia/Shanghai", the command would look like this:
sudo timedatectl set-timezone Asia/Shanghai
-
Verify the change: Enter the following command to verify that the time zone was changed successfully:
timedatectl
You will see the changed time zone displayed as "Time zone: YOUR_TIMEZONE" in the output.
-
Update system time: To update the system time to reflect the new time zone setting, the following command can be used:
sudo systemctl restart systemd-timesyncd
timedatectl
Through the above steps, you have successfully used commands to change the system time zone on Ubuntu .
Method 2: Modify /etc/timezone
the file
-
Open Terminal: Use the shortcut keys Ctrl+Alt+T or search for "Terminal" through the application menu to open the terminal.
-
Open the file with a text editor
/etc/timezone
: Enter the following command in Terminal to open the file with your favorite text editor/etc/timezone
:sudo vim /etc/timezone
This will
vim
open the file with an editor/etc/timezone
and require you to enter your administrator password. -
In the opened file, replace the current time zone with the new time zone you want to set. For example, if you were to set the timezone to "Asia/Shanghai", in the file it would read:
Asia/Shanghai
-
Save and close the file.
-
Update system time: Enter the following command to update the system time to reflect the new time zone setting:
sudo systemctl restart systemd-timesyncd
Through the above steps, you have /etc/timezone
successfully changed the time zone of the Ubuntu system by modifying the file.
Whether you choose to use timedatectl
the command or edit /etc/timezone
the file directly, the ultimate goal is to modify the system's time zone setting. However, using timedatectl
the command can be more convenient and reliable, as it automatically updates related files and links, ensuring that the system's time and time zone are in sync. Editing /etc/timezone
files may require additional manual steps, such as restarting services or updating time synchronization.
Correct time zone settings are important to ensure accurate times and dates, especially when operating across multiple time zones or coordinating with other systems. The correct time zone setting not only affects the time display in daily life, but also has an impact on system logs, scheduled tasks, and time stamps.
Hope this article helped you learn how to change the time zone on your Ubuntu system. Whichever method you choose, you can easily adjust your system's time zone settings to ensure accurate time and date display.