Logo

How to Easily Set or Change Timezone on Ubuntu

Try this guide with our instant dedicated server for as low as 40 Euros

time zone on ubuntu

Keeping the correct time is crucial to many operations of Ubuntu and similar Linux distributions. That’s why computer hardware comes with integrated clocks and supports software timekeeping to ensure the system always has the correct time and date.

Many operating systems use the National Institute of Standards and Technology (NIST) time servers. These servers provide accurate time and date information derived from the atomic clock maintained by the Institute.

Changing time zones to match the current location of the server is another important aspect of the system. 

In this tutorial, we will discuss how you can view and set time zone information and time/date on Ubuntu 20.x.

But first, let’s check out the need for setting time and date information.

Table Of Content

  1. Why is it Important to Set the Correct Time Zone on Ubuntu?
  2. The Prerequisites to Working with Time Zones in Ubuntu
  3. Check the Current Time Zone in Ubuntu 20.x
  4. Change the Time Zone on Ubuntu
  5. Manually Change the Time and Date on Ubuntu
  6. Synchronize System Clock with the NIST Clock
  7. Troubleshooting Common Time Zone Issues
  8. Conclusion
  9. FAQs

Why is it Important to Set the Correct Time Zone on Ubuntu?

Before we go into the details of changing the time zone on Ubuntu, it is important to understand why it is such a critical aspect of server and system security and management. Here are five reasons you should consider:

  • Logging and auditing system processes and components require accurate timestamps. 
  • Many automated processes, especially those involving troubleshooting, are time-sensitive.
  • The proper scheduling of cron jobs and the automated tasks depending upon the crontab need exact time settings to ensure the jobs run at the intended times.
  • The system should display the correct time to system users. This is important for avoiding confusion and errors.
  • Properly configured time zones are critical for synchronization with other systems and networks. Correct time and date information is vital for collaboration and data integrity in these processes.

The Prerequisites to Working with Time Zones in Ubuntu

Before trying out the commands and scenarios we will mention later on in this tutorial, make sure you have the following:

  • A system running a stable Ubuntu version 
  • A user account with root or sudo privileges

Check the Current Time Zone in Ubuntu 20.x

The first step in setting the correct time zone and time/date information in Debian-based distributions is to check the current values. 

We recommend the following two ways of checking this information.

Use the timedatectl Command to Check the Current Time Zone Information

On most Debian-based distributions, you can use the timedatectl command to view the currently set time zone information. The syntax of this command is as follows:

# timedatectl

timedatectl

Check the System Log Files for Time Zone Information

Another way of checking the current system time and date is to view the timestamps in the system logs. We recommend running the following command that uses tail to extract the ten most recent entries from the general /var/log/syslog file.

# sudo tail /var/log/syslog

sudo tail

Each entry in the log is preceded by a timestamp that shows the system’s time zone and time and date information. 

Change Time Zone on Ubuntu

Let’s start with changing the time zone on Ubuntu. 

We recommend starting by listing the current time zone information with the timedatectl command:

# timedatectl

timedatectl

You can see that the current time zone is set to Asia/Kolkata (IST, +0530).

Next, list all available time zones with the following command:

# timedatectl list-timezones 

timedatectl list-timezones

You can see that the time zones are presented in the Region/City combination. Ubuntu supports more than 80 time zone options. Finding your preferred time zone combination can be challenging. We recommended filtering out your preference with the following grep command syntax:

# timedatectl list-timezones | grep “[time zone]”

For instance, run the following command to find the time zone for Halifax, Canada. 

# timedatectl list-timezones | grep Hali

grep Hali

Now, you can change the current time zone by running the following timedatectl command:

# timedatectl set-timezone America/Halifax

You can now recheck the time zone information to verify that the time zone has been updated to your preferred choice. 

Set the Time Zone to UTC

If your Ubuntu machine is in a scientific or research setting, you may need to set your system’s time zone to Coordinated Universal Time (UTC) because many time calculations in science-focused software use this format. In addition, UTC (GMT and Zulu are comparable standards) is often preferred to avoid the confusion caused by the large number of time zones.

Run the following command to set the system’s time zone to UTC:

# timedatectl set-timezone UTC

Always check that the command was successfully executed (with a corresponding change in the system’s time zone settings) by running the timedatectl command. 

Manually Change the Time and Date on Ubuntu

You can change the system’s time and date individually by running specific timedatectl commands. Let’s take a closer look at these commands.

Change the Time on Ubuntu

You can set the time on your Ubuntu system to a specific value. Note that this value should be in the 24-hour format (HH:MM:SS).

The syntax of the command to set the system’s time is as follows:

# timedatectl HH:MM:SS

For instance, run the following command to set the system time to 2:22:22:

# timedatectl set-time 2:22:22

Important: This command updates the system’s hardware clock and the current system time. 

Change the Date on Ubuntu

Similarly, you can change the current system date to a different value. Note that this value should be in YYYY-MM-DD format. This format ensures that the year is expanded fully to avoid any confusion. 

For instance, run the following command to set the system date to May 10th, 2024:

# timedatectl set-time 2024-05-10

Update the System’s Hardware Clock

You can manually change the time zone of the system’s hardware clock by running the set-local-rtc command. Note that this clock is embedded in the system’s hardware.

You can opt to set the time zone to UTC or conventional local Region/Location format. 

For instance, run the following command to adjust the hardware clock to the local time zone:

# timedatectl set-local-rtc 1

Alternatively, run this command to adjust the hardware clock to UTC:

# timedatectl set-local-rtc 0

Synchronize System Clock with the NIST Clock

You can automate time and date values by automatically synchronizing the system clock with the NIST’s atomic clock. The process involves the synchronization of your server with the NIST server using the Network Time Protocol (NTP). 

Important: This process will fail if you don’t have the NTP on your server.

The command syntax for this synchronization is as follows:

# timedatectl set-ntp [value]

Where the value can be yes or no. 

So, in order to turn this synchronization on, run the following command:

# timedatectl set-ntp yes

Alternatively, you can turn the synchronization off with this command:

# timedatectl set-ntp no

Troubleshooting Common Time Zone Issues

Now that you have a good idea of manually and automatically setting the system time zone and time and date information on Ubuntu, let’s briefly consider some of the problems you may face with the process.

Incorrect Time Synchronization

If you have opted for automated updates to the system time via NTP and you see incorrect time information, you should check your internet connection. You should verify that your system has an active internet connection and that the system firewall (usually UFW) is not blocking NTP traffic.

Update the tzdata Package

tzdata is the standard Linux package containing information about time zones. The package provides a shared database that all software on the system can access for time zone conversions and related calculations. 

We recommend updating this package to the latest version to ensure your system has the most recent information about time zones. 

Setting Time and Date on Earlier Ubuntu Versions

If you are on an older Ubuntu version (earlier than Ubuntu 18.x), you may find that the commands mentioned earlier may not work. 

We present the following commands to set the time zones, time and date, and the hardware clock on your older Ubuntu system. 

Set the time with the following command:

# sudo date -s "HH:MM:SS"

Set the date with this command:

# sudo date -s "YY-MM-DD"

Conclusion

We discussed the idea of changing the time zone in Ubuntu. We also covered the essentials of viewing and setting time and date on Ubuntu systems. Time and date information is very critical for user experience and system security. 

If you are on an older version, we mentioned some Ubuntu commands that will help you change the system time and date. 

FAQs

Q. How can I set the timezone on Ubuntu using timedatectl?

 To set the timezone on Ubuntu, open a terminal and run sudo timedatectl set-timezone <your-timezone>. For example, sudo timedatectl set-timezone America/New_York.

Q. How do I check the current timezone setting on Ubuntu?

 You can view the current timezone setting by running the command timedatectl status. This will display the current local time, UTC time, and the configured timezone.

Q. What is the command to list all available timezones in Ubuntu?

 Use timedatectl list-timezones to list down the available timezones in the terminal. You can then choose the appropriate timezone for your system.

Q. How does changing the timezone affect cron jobs on Ubuntu?

 Changing the timezone on Ubuntu will affect cron jobs because they are scheduled based on the system’s local time. Ensure you verify your cron job schedules after changing the timezone to maintain the correct timing.

Q. Is it possible to set the timezone to UTC using timedatectl?

 Yes, you can set the timezone to UTC by running sudo timedatectl set-timezone UTC. This will configure your system to use Coordinated Universal Time.

Q. How can I revert to the previous timezone if needed?

 If you need to revert to a previous timezone, simply run sudo timedatectl set-timezone <previous-timezone>. You need to know the exact name of the previous timezone.

Q. Should I reboot the Ubuntu system after changing the timezone?

 No, changing the timezone using timedatectl does not require a system reboot. The changes take effect immediately.

Q. Can I automate timezone changes using a script?

 Yes, you can automate timezone changes by writing a script that includes the timedatectl set-timezone command. Schedule the script using cron jobs to run at specified times if needed.

Q. How do I ensure my timezone changes are permanent?

Timezone changes made with timedatectl are permanent and persist across reboots. Verify the setting with timedatectl status to ensure it is correctly applied.

Q. Why should I make sure that my Ubuntu system has the correct timezone?

 Setting the correct timezone ensures accurate timestamps in logs, proper scheduling of cron jobs, and correct local time display for users, which is crucial for system administration and troubleshooting.

Try this guide with our instant dedicated server for as low as 40 Euros