Two ways to change the system time zone on Ubuntu

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 timedatectlcommands and directly editing /etc/timezonefiles. Let's take a look at the specific steps of these two methods.

Method 1: Use timedatectlthe command

  1. open terminal

  2. Run the command: Enter the following command in a terminal to get the current time zone setting:

    timedatectl
    
  3. List Available Time Zones: The command timedatectlwill display the current time zone setting along with other relevant information. Take note of the ID of the time zone you want to change.

  4. 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
    
  5. 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.

  6. 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
    

timedatectlThrough the above steps, you have successfully used commands to change the system time zone on Ubuntu .

Method 2: Modify /etc/timezonethe file

  1. Open Terminal: Use the shortcut keys Ctrl+Alt+T or search for "Terminal" through the application menu to open the terminal.

  2. 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 vimopen the file with an editor /etc/timezoneand require you to enter your administrator password.

  3. 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
    
  4. Save and close the file.

  5. 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/timezonesuccessfully changed the time zone of the Ubuntu system by modifying the file.

Whether you choose to use timedatectlthe command or edit /etc/timezonethe file directly, the ultimate goal is to modify the system's time zone setting. However, using timedatectlthe 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/timezonefiles 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.

Guess you like

Origin blog.csdn.net/kaka_buka/article/details/131540461