In this guide, we want to teach you How To Use the timedatectl Command in Linux.
The timedatectl command is a useful utility available on almost all Linux distributions that use systemd.
Using this utility, you can control the current timezone, date, and time. You can even use it to enable automatic time synchronization with remote NTP servers.
Additionally, when you set the time using timedatectl, it will also reconfigure any real-time clocks (RTC) connected to your system to use the correct time.
How To Use timedatectl Command in Linux with Examples
This guide will show you how to use this Linux command to control the current timezone, date, and time.
Now follow the steps below to complete this guide.
Display Current Status with timedatectl
Running the “timedatectl” with no additional parameters will display your current time and date and your time zone. Your current synchronization status is also displayed.
Simply run the command below:
Output Local time: Thu 2022-09-15 12:22:05 CEST Universal time: Thu 2022-09-15 10:22:05 UTC RTC time: Thu 2022-09-15 10:22:06 Time zone: Europe/Berlin (CEST, +0200) System clock synchronized: yes NTP service: active RTC in local TZ: no
Set Time Zone with timedatectl Command
Your time displayed will always be based on the time zone that has been configured on your Linux system.
You can list all available time zones on your Linux system by running the timedatectl command:
Output Africa/Abidjan Africa/Accra Africa/Algiers Africa/Bissau Africa/Cairo Africa/Casablanca Africa/Ceuta Africa/El_Aaiun Africa/Johannesburg ... Africa/Windhoek America/Adak America/Anchorage America/Araguaina America/Argentina/Buenos_Aires ...
To set a time zone you can specify it by names like EST or GMT, or you can pick a location in the same time zone as you, like London or New York.
If you wanted to change the current time zone to “America/New_York”, you can use the command below:
timedatectl set-timezone "America/New_York"
Then check your current time zone status with the command below:
Output Local time: Thu 2022-09-15 06:29:44 EDT Universal time: Thu 2022-09-15 10:29:44 UTC RTC time: Thu 2022-09-15 10:29:45 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no
From the above output, you can see that the time zone has now been changed to “America/New_York”. Notice that the time has also changed now to match the time zone.
Set Time and Date Manually in Linux
As you know, using time synchronization and NTP is the preferred way to keep your computer’s time and date accurately. If you plan to change your computer’s date or time you’ll probably get an error, telling you that time synchronization is in use.
timedatectl set-time 09:30:00
Output Failed to set time: Automatic time synchronization is enabled
So you need to stop the time synchronization service. To do this, run the command below:
systemctl stop systemd-timesyncd.service
At this point, you can set your time and date manually on your Linux server with the timedatectl command. For example:
timedatectl set-time "2022-09-30 11:30:00"
Check your status:
Output Local time: Fri 2022-09-30 11:30:25 EDT Universal time: Fri 2022-09-30 15:30:25 UTC RTC time: Fri 2022-09-30 15:30:25 Time zone: America/New_York (EDT, -0400) System clock synchronized: no NTP service: inactive RTC in local TZ: no
The date and time have changed. Also, note the computer is using a false UTC time. We’re also informed that the system clock is not being synchronized and the NTP service is inactive.
As soon as you restore the time synchronization service the time is retrieved and all of the details are correctly reset:
systemctl restart systemd-timesyncd.service
Output Local time: Thu 2022-09-15 06:41:29 EDT Universal time: Thu 2022-09-15 10:41:29 UTC RTC time: Thu 2022-09-15 10:41:30 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no
At this point, you learn How To Use the timedatectl command in Linux to control your current timezone, date, and time.
Hope you enjoy it.
You may be interested in these articles: