1. To display the current time and date on the system, use the timedatectl command from the command line as follows:
# timedatectl status
Check time and date
In the screencast above, the RTC time is the hardware clock time.
2. The time on your Linux system is always managed by the time zone set on the system. To check your current time zone, do the following:
#timedatectl
or
#timedatectl | grep time
Check Linux time zone
3. To see all available time zones, run the following command:
# timedatectl list-timezones
List all timezones in Linux
4. To find the local time zone based on your location, run the following command:
# timedatectl list-timezones | egrep -o "Asia/B.*"
# timedatectl list-timezones | egrep -o "Europe/L.*"
# timedatectl list-timezones | egrep -o "America/N.*"Find local time zone in Linux
5. To set the local timezone in Linux, we will use the set-timezone switch as shown below.
# timedatectl set-timezone "Asia/Kolkata"
It is always recommended to use and set UTC.
# timedatectl set time zone UTC
Set UTC time in Linux
You need to enter the correct time zone name, otherwise you may get an error when changing the time zone, in the example below, the time zone "Asia/Kolkata" is incorrect, thus causing an error.
Set the correct time zone in Linux
How to Set Time and Date in Linux
6. You can use the timedatectl command to set the date and time of the system as follows:
To set the time only, we can use the set time switch and the time format of HH:MM:SS (hours, minutes, and seconds).
timedatectl set-time 15:58:30
When setting the date as shown above, you may receive the following error:
Failed to set time: NTP unit is active
7. The error says the NTP service is active. You need to disable it with the following command.
# systemctl disable --now chronyd
8. To set the date and time, we can use the set time switch, the date format is YY:MM:DD (year, month, day), and the time format is HH:MM:SS (hour, minute, second).
# timedatectl set-time '2015-11-20 16:14:50'
How to Find and Set the Hardware Clock in Linux
9. To set the hardware clock to UTC, use the set-local-rtc boolean-value option as follows:
First determine if your hardware clock is set to the local time zone:
#timedatectl | grep local
Set your hardware clock to the local time zone:
# timedatectl set-local-rtc 1
Set your hardware clock to Coordinated Universal Time (UTC):
# timedatectl set-local-rtc 0
Set the hardware clock to UTC
Synchronize the Linux system clock with a remote NTP server
NTP stands for Network Time Protocol is an internet protocol used to synchronize system clocks between computers. The timedatectl utility enables you to automatically synchronize your Linux system clock with a remote server group using NTP.
Note that you must have NTP installed on your system to enable automatic time synchronization with an NTP server.
To start automatic time synchronization with a remote NTP server, enter the following command in the terminal.
# timedatectl set-ntp true
To disable NTP time synchronization, type the following command in the terminal
# timedatectl set-ntp false
