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|
timedatectl Command Examples
1. Check the current system clock time:
2. Set the local time of the system clock directly:
# timedatectl set-time "yyyy-MM-dd hh:mm:ss"
3. List available timezones:
# timedatectl list-timezones
4. Set the system timezone:
# timedatectl set-timezone timezone
5. Enable Network Time Protocol (NTP) synchronization:
# timedatectl set-ntp on
6. We can change the date using the following command:
# timedatectl set-time 2014-07-19
7. The time can be set using the same option with time as the argument, shown as follows:
# timedatectl set-time 23:02:23
8. 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
9. 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
10. 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.