
Introduction
The timedatectl utility is distributed as part of the systemd system and service manager.
It allows you to review and change the configuration of the system clock.
This tool can be used to change the current date and time, set the time zone or enable automatic synchronization of the system clock with a remote server.
To display current date and time along with detailed information about the configuration of the system and hardware clock, run the timedatectl command with no additional command line options:
1 2 3 4 5 6 7 8 9 |
[root@centos7-vm ~]# timedatectl Local time: Tue 2018-03-13 18:13:58 EAT Universal time: Tue 2018-03-13 15:13:58 UTC RTC time: Tue 2018-03-13 15:13:58 Time zone: Africa/Nairobi (EAT, +0300) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a |
To change the current time, we have to ensure automatic time synchronization is disabled. Type the following in the shell prompt as root to disable ntp
1 |
timedatectl set-ntp false |
Next, we set the current time in the format HH:MM:SS.
Replace HH with an hour, MM with a minute, and SS with a second, all typed in two-digit form.
1 |
timedatectl set-time 18:20:33 |
By default, the system is configured to use UTC. To configure your system to maintain the clock in the local time, run the timedatectl command with the set-local-rtc option as root:
1 |
timedatectl set-local-rtc true |
To change the current date, type the following at a shell prompt as root:
1 |
timedatectl set-time 2018-03-14 |
Make sure to disable ntp before running the command.
Changing the date without specifying the current time results in setting the time to 00:00:00.
Therefore, to set the date to 14th March 2018 maintaining the current time as 18:33 hrs, run;
1 |
timedatectl set-time "2018-03-14 18:33:00" |
Working with timezones
With timedatectl, you can also view and change system timezones.
To list available timezones, run
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@centos7-vm ~]# timedatectl list-timezones Africa/Abidjan Africa/Accra Africa/Addis_Ababa Africa/Algiers Africa/Asmara Africa/Bamako Africa/Bangui Africa/Banjul Africa/Bissau Africa/Blantyre Africa/Brazzaville |
To set current timezone to Africa/Nairobi run
1 |
timedatectl set-timezone Africa/Nairobi |
Working with NTP
The timedatectl command also allows you to enable automatic synchronization of your system clock with a group of remote servers using the NTP protocol.
Enabling NTP enables the chronyd or ntpd service, depending on which of them is installed.
The NTP service can be enabled and disabled using a command as follows:
1 |
timedatectl set-ntp true |
The command will fail if an NTP service is not installed. Make sure either chronyd or ntpd is installed.
harun
Latest posts by harun (see all)
- Reset Linux Root Password Using Rescue CD - September 21, 2018
- Extending Linux Root Partition using LVM - June 14, 2018
- Parted Utility - April 11, 2018