timedatectl command in Linux allows you to query and change the system clock and its settings. It comes as part of systemd, a replacement for the sysvinit daemon used in the GNU/Linux and Unix systems.
In this article, we will discuss this command and the features it provides using relevant examples.
Note – All examples described in this article are tested on GNU bash, version 4.3.11(1).
Display system date/time information
Simply run the command without any command line options or flags, and it gives you information on the system’s current date and time, as well as time-related settings. For example, here is the output when I executed the command on my system:
$ timedatectl Local time: Sat 2014-11-08 05:46:40 IST Universal time: Sat 2014-11-08 00:16:40 UTC Timezone: Asia/Kolkata (IST, +0530) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
So you can see that the output contains information on LTC, UTC, and time zone, as well as settings related to NTP, RTC and DST for the localhost.
Update the system date or time using the set-time option
To set the system clock to a specified date or time, use the
set-time option followed by a string containing the new date/time information. For example, to change the system time to 6:40 am, I used the following command:
$ sudo timedatectl set-time "2014-11-08 06:40:00"
and here is the output:
$ timedatectl Local time: Sat 2014-11-08 06:40:02 IST Universal time: Sat 2014-11-08 01:10:02 UTC Timezone: Asia/Kolkata (IST, +0530) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a
Observe that the Local time field now shows the updated time. Similarly, you can update the system date, too.
Update the system time zone using the set-timezone option
To set the system time zone to the specified value, you can use the
set-timezone option followed by the time zone value. To help you with the task, the
timedatectl command also provides another useful option.
list-timezones provides you with a list of available time zones to choose from.
For example, here is the scrollable list of time zones the
timedatectl command produced on my system:
To change the system’s current time zone from Asia/Kolkata to Asia/Kathmandu, here is the command I used:
$ timedatectl set-timezone Asia/Kathmandu
and to verify the change, here is the output of the
$ timedatectl Local time: Sat 2014-11-08 07:11:23 NPT Universal time: Sat 2014-11-08 01:26:23 UTC Timezone: Asia/Kathmandu (NPT, +0545) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a
You can see that the time zone was changed to the new value.
You can also use the
timedatectl command to configure RTC (real-time clock). For those who are unaware, RTC is a battery-powered computer clock that keeps track of the time even when the system is turned off. The
timedatectl command offers a
set-local-rtc option which can be used to maintain the RTC in either local time or universal time.
This option requires a boolean argument. If 0 is supplied, the system is configured to maintain the RTC in universal time:
$ timedatectl set-local-rtc 0
but in case 1 is supplied, it will maintain the RTC in local time instead.
$ timedatectl set-local-rtc 1
A word of caution: Maintaining the RTC in the local time zone is not fully supported and will create various problems with time zone changes and daylight saving adjustments. If at all possible, use RTC in UTC.
Another point worth noting is that if
set-local-rtc is invoked and the
--adjust-system-clock option is passed, the system clock is synchronized from the RTC again, taking the new setting into account. Otherwise the RTC is synchronized from the system clock.
Configure NTP-based network time synchronization
NTP, or Network Time Protocol, is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks. It is intended to synchronize all participating computers to within a few milliseconds of UTC.
timedatectl command provides a
set-ntp option that controls whether NTP based network time synchronization is enabled. This option expects a boolean argument. To enable NTP-based time synchronization, run the following command:
$ timedatectl set-ntp true
To disable, run:
$ timedatectl set-ntp false
As evident from the examples described above, the
timedatectl command is a handy tool for system administrators who can use it to to adjust various system clocks and RTC configurations as well as poll remote servers for time information. To learn more about the command, head over to its man page.
Our latest tutorials delivered straight to your inbox