Linux hardware time and system time

I. Overview

  Linux is divided into hardware time and system time. The two times run independently after the start, and there may be errors after long-term operation.

  • Hardware time (Real Time Clock, referred to as RTC) : the clock time of the main board, there is a battery on the main board, which continuously supplies power for the main board clock after shutdown, and consumes very little power. After fully charged, it can continue to supply power for one or two years after shutdown. After booting, the system will automatically synchronize the time by default. The battery on the main board also has a lifespan, generally more than 5 years, and the operating environment is good. Frequent power-on will prolong the life, and long-term idle time will shorten the life.
  • System Clock : Linux system time, the time viewed by the date command, the time will be reset to the hardware time by default when the system restarts.

Two, common commands

--查看当前硬件时间
hwclock

--修改当前硬件时间
hwclock --set --date "20230413 10:00:00"

--查看当前系统时间
date

--修改当前系统时间
date -s "20230413 10:00:00"

--系统时间去同步硬件时间
hwclock -s

[root@dbha3 ~]# hwclock;date
Thu 13 Apr 2023 11:01:17 AM CST  -0.334388 seconds
Thu Apr 13 10:00:16 CST 2023
[root@dbha3 ~]# hwclock -s
[root@dbha3 ~]# hwclock;date
Thu 13 Apr 2023 11:01:36 AM CST  -0.755660 seconds
Thu Apr 13 11:01:36 CST 2023

--硬件时间去同步系统时间
hwclock -w

[root@dbha3 ~]# hwclock;date
Thu 13 Apr 2023 10:00:02 AM CST  -0.663228 seconds
Thu Apr 13 11:04:18 CST 2023
[root@dbha3 ~]# hwclock -w
[root@dbha3 ~]# hwclock;date
Thu 13 Apr 2023 11:04:30 AM CST  -0.177063 seconds
Thu Apr 13 11:04:30 CST 2023

おすすめ

転載: blog.csdn.net/songyundong1993/article/details/130172676