1. Introduction
There are two clocks of hardware clock and system clock in Linux. The hardware clock is the clock device on the motherboard, which is usually the clock that can be set on the BIOS screen. This time there is battery-powered maintenance on the motherboard, if the motherboard battery is exhausted, if the power outage, restore to the factory settings. The system clock refers to the clock in the kernel. All Linux-related instructions and functions are programmed to read the system clock. Because there are two different clocks, there is a difference between them. When Linux starts, the system clock reads the settings of the hardware clock, and then the system clock runs independently.
For system time, we can use the date command to view:
[Email protected]:~$ Date
Wed APR 15:52:23 CST 2015
Hardware time, using the Hwclock command to view
[Email protected]:~$ sudo hwclock–show//hardware time requires root privileges
[sudo] password for unicom:
Wed Apr 16:13:42 2015-0.844670 seconds
2. Time Settings
The time set with the date command does not modify the hardware time of the system, and the hardware time is still loaded after the system restarts, which is an issue that often causes the date setting time to expire.
The correct approach is to set the system time, then perform a time synchronization to the hardware clock, of course, the direct setting of the hardware clock is also possible.
Date sets the system clock.
# date --set “04/15/15 16:19" (月/日/年 时:分:秒)
Synchronize the system time to the hardware clock:
# sudo hwclock --systohc
Or# sudo hwclock -w
To set the hardware time method directly:
# sudo hwclock --set --date="04/15/15 16:19" (月/日/年 时:分:秒)
Common command parameters for hardware clocks
Command Parameters |
Description |
-r,–show |
Read and print the hardware clock (read hardware clock and print result) |
-s,–hctosys |
Synchronizing the hardware clock to the system clock (set the time from the hardware clock) |
-w,–systohc |
Synchronizing the system clock to the hardware clock (set the hardware clock to the current system time) |
Linux system time and hardware time settings