Introduction
Modern operating systems synchronize time using the Network Time Protocol (NTP). NTP communicates with time servers connected to highly precise atomic clocks and downstream servers that distribute time globally.
Occasionally, you may need to manually synchronize time with NTP servers due to a network disruption or misconfiguration.
This guide shows you how to check and adjust Ubuntu's time, date, and timezone.
Prerequisites
- Access to the command line or terminal window.
- Some operations require sudo or root privileges.
Display Current Time, Date, and Timezone in Ubuntu
Most Linux distributions, such as Ubuntu, Fedora, Debian, and Arch, include the timedatectl utility. Access the command line and enter the timedatectl
command to display the current time and date information:
timedatectl
The output provides the local time and date, universal time (UTC), and configured timezone and informs you if time synchronization is enabled.
Note: Learn how to set up time synchronization on Debian.
Change Time, Date, and Timezone in Ubuntu Using timedatectl
You can also use the timedatectl
command to edit time, date, and timezone settings in Ubuntu.
Set Timezone in Ubuntu Using timedatectl
To synchronize a system with a timezone of your choosing:
1. Enter the following command to list the names of available timezones:
timedatectl list-timezones
2. The timezone list is extensive and sorted alphabetically. Use the grep command to filter the list by keyword:
timedatectl list-timezones | grep [keyword]
Substitute [keyword]
for any keyword you wish, such as America, Asia, or New_York. If you get an error, double-check your spelling and ensure you use capital letters correctly.
3. Use the following command to set the timezone:
timedatectl set-timezone Region/Location
Replace Region/Location
with a name from the timezone list.
Set Universal Time (UTC) in Ubuntu Using timedatectl
Coordinated Universal Time (UTC) is used to synchronize time across different time zones. This is especially useful in the cloud and containerized environments, as it eliminates issues caused by local time shifts, like daylight saving time. Synchronize your system with UTC using the following command:
timedatectl set-timezone UTC
There is no immediate output; however, you can check the applied settings with timedatectl
.
Note: GMT and Zulu Time are often used to refer to UTC. They are equivalent terms when fractions of a second are not relevant.
Sync Time with NTP in Ubuntu Using timedatectl
Set the Ubuntu system to synchronize with NTP time servers using the following command:
timedatectl set-ntp yes
The system does not provide immediate output. Use the timedatectl
command to verify the changes have been applied.
Change Time in Ubuntu Using timedatectl
If you want to adjust the time manually, you must turn off NTP synchronization first:
timedatectl set-ntp no
To set the time to your specifications, use the following command:
timedatectl set-time 21:45:53
The time format is HH:MM:SS (Hours:Minutes:Seconds).
Change Date in Ubuntu Using timedatectl
Ensure that the automatic NTP synchronization is turned off:
timedatectl set-ntp no
Use the set-time
option to define the date on the system:
timedatectl set-time 2024-10-28
The date format is YYYY-MM-DD (Year-Month-Day).
Change Time, Date, and Timezone in Ubuntu via GUI
Some users may prefer to adjust system settings through the Ubuntu graphical interface in a user-friendly and interactive environment.
To modify time, date, and timezone settings via the Ubuntu GUI:
1. Open the Show Applications menu in the bottom-left corner.
2. Type Date & Time in the search field and select the Date & Time option.
The Date & Time panel contains all the options for adjusting the system's time, date, and timezone settings.
Set Timezone in Ubuntu Using the GUI
To change the timezone in the Ubuntu GUI:
1. Access the Time & Date panel.
2. Disable the Automatic Time Zone option.
3. Click the Time Zone tab.
4. Search for your city or region and select the desired option in the Select Time Zone popup.
Close the popup window and exit the Settings app.
Set Universal Time (UTC) in Ubuntu Using the GUI
Depending on the version, Ubuntu may not explicitly list Coordinated Universal Time (UTC) as a timezone. For example, this is true in Ubuntu 24.04. However, it can be set indirectly by selecting London or Reykjavik, which follow UTC. To synchronize time with UTC in Ubuntu:
1. Access the Date & Time panel.
2. Turn off the Automatic Time Zone toggle.
3. Click the Time Zone field.
4. Search for and click London or Reykjavik in the list.
Your system is now set to follow UTC.
Sync Time with NTP in Ubuntu Using the GUI
To automatically synchronize your system clock with NTP:
1. Access the Date & Time panel in the Settings app.
2. Enable the Automatic Date & Time toggle.
The system now syncs time with NTP servers as long as the feature is turned on and connected to the internet.
Change Time and Date in Ubuntu Using the GUI
To change the time and date within the Ubuntu GUI:
1. Access the Date & Time panel.
2. Disable the Automatic Date & Time option.
3. Click the Date & Time field.
4. Use the corresponding fields and buttons in the popup to adjust the time, month, day, and year.
Close the popup and exit the Settings menu. The new settings are applied immediately.
Hardware Clock vs. System Clock
Modern devices maintain two types of clocks to keep track of time. The system clock is managed by the device's operating system, for example, Ubuntu. It synchronizes with online time servers when connected to the internet. Timestamps for files, scheduled tasks, and logs are based on this clock.
The hardware clock or Real-Time Clock (RTC) helps the system track time when disconnected from the internet or powered off. It uses a battery and a quartz crystal oscillator to maintain time without external power or a network connection. When the system boots up again, it reads the hardware clock to initialize the system clock. Once the system is up and running, it can synchronize with NTP servers to correct potential inaccuracies.
How to Sync Hardware Clock in Ubuntu
Hardware clocks can drift and lose accuracy, especially if a system has been turned off or disconnected from a network for a long time. Occasionally, it may be necessary to align the hardware clock (RTC) with Coordinated Universal Time (UTC).
Align Hardware Clock with UTC
Enter the following command to set the hardware clock to use UTC:
timedatectl set-local-rtc 0
This is the recommended setting for most systems. NTP servers synchronize with UTC, and operating systems expect the hardware clock to store time in UTC.
There is no confirmation message that the change has been applied. You can verify the change using the timedatectl
command:
timedatectl
The output confirms that the RTC time is using UTC.
Set Time, Date, and Timezone in Older Ubuntu Versions
Older Ubuntu versions, such as Ubuntu 14.04 or earlier, may not support the timedatectl utility. If timedatectl is not available, use the following commands to manage system and hardware clocks from the command line. The commands work on both older and newer Ubuntu versions.
Display Date and Time
Use the date command to display the current date and time of the operating system:
date
Adjust Date
To change the system date, type:
sudo date -s "YYYY-MM-DD"
Replace YYYY-MM-DD
with the desired Year-Month-Day.
Adjust Time
To change the system time, enter:
sudo date -s "HH:MM:SS"
Replace HH:MM:SS
with the desired Hour:Minute:Second. The time and date can be modified in a single command:
sudo date -s "YYYY-MM-DD HH:MM:SS"
This is more convenient when you need to define both the date and time at once.
Display RTC Date and Time
Display the time kept by the hardware clock (RTC) with any of the following commands:
sudo hwclock -r
or
sudo hwclock --show
or
sudo hwclock --show --verbose
Note: Some versions may not support the --verbose
option, and it may not work on a virtual machine.
Display RTC Time in UTC Format
To display the hardware clock time in UTC format, enter:
sudo hwclock --show --utc
Change RTC Time
Change the time kept by the hardware clock using the following command:
sudo hwclock --set --date "YYYY-MM-DD HH:MM:SS"
Replace YYYY-MM-DD
with the desired Year-Month-Day, and HH:MM:SS
with the desired Hour:Minute:Second.
Sync OS Time with RTC
To set the system clock based on the hardware clock (RTC), run:
sudo hwclock --hctosys
Sync RTC Time with OS
To synchronize the hardware clock (RTC) with the system clock, use:
sudo hwclock --systohc
Conclusion
The article showed you how to set the time, date, and timezone on your Ubuntu system. The best course of action for most systems is to synchronize time with NTP servers automatically.
If running a MySQL server, also learn how to configure the MySQL server timezone.