A new command that was introduced in systemd-based distributions that enables you to manage many aspects of time is timedatectl. When used without any arguments, this command shows detailed information about the current time and date. It also displays the time zone your system is in, in addition to information about the use of NTP network time and information about the use of DST.
# timedatectl Local time: Mon 2019-06-10 08:27:57 EDT Universal time: Mon 2019-06-10 12:27:57 UTC RTC time: Mon 2019-06-10 12:27:57 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no
Most Common Options with timedatectl Command
|status||Shows the current time settings|
|set-time TIME||Sets the current time|
|set-timezone ZONE||Sets the current time zone|
|list-timezone||Shows a list of all time zones|
|set-local-rtc [0|1]||Controls whether the RTC (the real-time clock, normally referred to as the hardware clock) is in local time|
|set-ntp [0|1]||Controls whether NTP is enabled|
If you encounter below error:
timedatectl: command not found
you may try installing below package as per your choice of distribution.
|Debian||apt-get install systemd|
|Ubuntu||apt-get install systemd|
|Arch Linux||pacman -S systemd|
|Kali Linux||apt-get install systemd|
|CentOS||yum install systemd|
|Fedora||dnf install systemd|
|Raspbian||apt-get install systemd|
timedatectl Command Examples
1. We can change the date using the following command:
# timedatectl set-time 2014-07-19
2. The time can be set using the same option with time as the argument, shown as follows:
# timedatectl set-time 23:02:23
3. NTP time synchronization can be enabled and disabled with the following command; though, it uses the news system service manager to enable and disable the time service:
# timedatectl set-ntp yes
4. To list available time zones:
# timedatectl list-timezones
5. If you have found the right time zone, write it down and use it in the next command; for example, if you are located in Germany and are near the city of Berlin, use the following command:
# timedatectl set-timezone Europe/Berlin
6. Use timedatectl again to check if your local time is correct now:
# timedatectl | grep "Local time"
The newer systemd-based distributions include a simple command to display and manage time and date settings on the host system: timedatectl. This really is a godsend to us as administrators; even if we only use the command to display the output, this one command will display the time, timezone, and NTP settings.