3. Linux系统中RTC测试命令

3.1. date和hwclock

  • date 命令用于查询或设置当前 Linux 系统(软件)时钟。Linux 启动时,系统时钟会从硬件时钟(RTC)同步。

  • hwclock 命令用于查询或设置硬件时钟(RTC)的时间。

示例:设置系统时间

date "2020-10-17 9:48:30"
# Sat Oct 17 09:48:30 CST 2020

示例:读取系统时间

date
# Sat Oct 17 09:48:34 CST 2020

示例:查询硬件时钟(RTC)时间

hwclock
# Sat Oct 17 09:56:03 2020  0.000000 seconds

示例:将系统时间写入硬件时钟

hwclock -w

示例:将硬件时钟同步到系统时间

hwclock -s