How to manage Linux system time and date in systemd
Timedatectl is a Linux application used to query and modify the system time and configuration. It is part of systemd System Service Management and allows you to check and modify system clock configurations.
In this article, we will cover all aspects of this small but important application.
Current System Time status
To view the current date/time of the system, and use a command without any parameters to view the current system time configuration, you can do this:
- # Timedatectl
The input result is as follows:
Modification date
To modify the system date, you can simply use timedatectl to set the time command, followed by the YYYY-MM-DD format of the date, YYYY represents the year, MM represents the two digits of the month, DD represents the day of two digits. For example, if you want to change the date to February 4, 2015, you should use the following command:
- # Timedatectl 2015-02-04
Modification time
To modify the time, you can use the tool in the same way, but the format is HH: MM: SS. HH indicates the 24-hour clock, and MM indicates the minute, SS stands for seconds. To set the current time to 22:04:43, run the following command:
- # Timedatectl 22:04:43
Modify Time Zone
Setting the correct time zone is the key to maintaining time synchronization, especially when you use the NTP protocol for synchronization. First, you should use the list-timezones option to list available time zones in your region. You can also use grep and more to make the format easier to read:
- # Timedatectl list-timezones | grep America | more
This will display a simple scrolling list format.
Then you will know how the time zone you want to set is named, and then use the following command to modify it:
- # Timedatectl set-timezone America/Los_Angeles
Set local clock
Real-time clock (RTC), usually called a hardware clock, is completely independent of the current operating system status and can even work when the computer is shut down. You can configure the system to use international Time (UTC) or local time to correct RTC. Note that using the local time zone to correct RTC is not fully supported, and there may be many problems caused by time zone changes and daylight saving time adjustments. If possible, correct RTC in UTC mode. The only problem with this approach is that other operating systems may not fully support it (if you run two operating systems on the same machine ).
Use the following command to correct RTC in UTC mode:
- # Timedatectl set-local-rtc 0
Use local time correction, use:
- # Timedatectl set-local-rtc 1
Set NTP Synchronization
Network Time Protocol (NTP) is a network protocol for clock synchronization between computer systems with group switching and variable data latency. NTP is designed to use Coordinated Universal Time (UTC) in milliseconds to synchronize all participating computers. If you want to set NTP synchronization, you can use the set-ntp option. Use "no" to disable NTP synchronization and use "yes.
- # Timedatectl set-ntp yes
Linux boot mode: systemd upstart sysV
Why is systemd so quickly adopted?
Systemd and sysVinit Color comparison table
Linux Kernel EMD -- start/stop/restart the service in RHEL/CentOS 7
So useful! Run the systemd command to manage the Linux system!
This article permanently updates the link address: