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. 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.
When the system time is set with the date command, the hardware clock is not modified, so the system time is still read hardware time after the system restarts, which is why the date setting fails to the cause.
Therefore, the system time needs to be synchronized to the hardware clock after the system time has been set.
Clock/hwclock:
display and set the hardware clock (query and set the hardware clock (RTC)), the two commands are the same. Rtc=real time Clock, which is the hardware clock.
Command parameters:
-R,--show reads and prints the hardware clock (read hardware clock and print result)-S,--hctosys synchronizes the hardware clock to the system clock (set the Hardware clock)-W,--SYSTOHC synchronizes the system clock to the hardware clock (set the hardware clock to the current system time)
command example:
1. View Hardware Clock
March 27, 2014 Thursday 11:03 50 sec -0.328520 seconds
[Email protected] ~]# Hwclock-r
March 27, 2014 Thursday 11:03 53 sec -0.797264 seconds
[Email protected] ~]# Hwclock--show
March 27, 2014 Thursday 11:04 01 sec -0.672267 seconds
2. Clock is the same as Hwclock
[Email protected] ~]# type-a hwclockhwclock is/sbin/hwclockhwclock is/usr/sbin/hwclock[[email protected] ~]# ll/sbin/ Hwclock/usr/sbin/hwclock-rwxr-xr-x. 1 root root 46940 November 23:27/sbin/hwclocklrwxrwxrwx. 1 root root 18 March 19:27/usr/sbin/hwclock. /.. /sbin/hwclock[[email protected] ~]# type-a clockclock is/sbin/clock[[email protected] ~]# ll/sbin/clock lrwxrwxrwx. 1 root root 7 March 19:27/sbin/clock-Hwclock
3. Synchronizing the system time to the hardware clock
[[email protected] ~]# hwclock2014 March 27 Thursday 18:50 51 seconds -0.312960 Seconds[[email protected] ~]# date2014 year March 27 Thursday 10:50:55 Cst[[email protected] ~]# hwclock-w[[email protected] ~]# hwclock2014 year March 27 Thursday 10:51 15 seconds -0.875387 Seconds
Synchronizing network time to system time
[Email protected] ~]# ntpdate 210.72.145.4427 Mar 11:11:24 ntpdate[4766]: Adjust time server 210.72.145.44 offset 0.01140 1 sec
210.72.145.44 (Official time synchronization server IP domain name of Xi ' an timing center, China)
After synchronizing the network time to the system time, you can use HWCLOCK-W to synchronize the system time to hardware time.
Modify Time Zone
It is possible that some systems will fail after a reboot after performing the above two steps, so time zone modifications are required.
[Email protected] ~]# Tzselect #按照提示进行选择时区
[Email protected] ~]# Ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime
Modify the system time profile
[Email protected] ~]#/etc/sysconfig/clock
#打开clock文件, change the relevant content to the following content
Arc=false
Zone= "Asia/shanghai"
Rebooting the system
[email protected] ~]# reboot
(Article Source: http://www.cnblogs.com/shockerli/p/linux-time-set.html)