The difference between RTC time and Local time and Linux setting time zone and modification time

RTC time和Local time

在Linux系统中存在两个时钟时间,分别是
硬件时钟RTC(Real Time Clock) 系统时钟(System Clock)

硬件时钟是指的在主板上的时钟设备,也就是通常可以在BIOS画面设置的时钟,即使关机状态也可以计算时间。
而系统时钟则是指Kernel中的时钟,其值是由1970年1月1日00:00:00 UTC时间至当前时间所经历的秒数总和。
当Linux启动的时候,系统时钟会读取硬件时钟的设定,之后系统时钟独立运作。
长时间运行两者可能将会产生误差。
另外所有的Linux相关指令都是读取系统时钟指定的,如date。

NTP

NTP,网络时间协议,使用 123/udp 端口进行网络时钟同步
NTP 是仍在使用中的最古老的网络传输协议之一(1985 年前开始)。

See if the clock is synced with the internet

OpenSUSE:~ # timedatectl      ##openSUSE15.1下查看
Local time: Tue 2020-05-05 10:38:53 CST      ##本地时间
Universal time: Tue 2020-05-05 02:38:53 UTC    ##协调世界时
RTC time: Tue 2020-05-05 02:38:51          ##硬件时间
Time zone: Asia/Shanghai (CST, +0800)        ##时区,我这里为东8Network time on: yes       ##NTP时间同步是否开启,yes表示是
NTP synchronized: yes        ##如果和远程NTP服务器成功同步,显示为yes
RTC in local TZ: no            ##no表示硬件时钟设置为协调世界时(UTC),yes表示硬件时钟设置为本地时间
root@HP:~# timedatectl      ##Ubuntu18.04下查看,下面的说明都以Ubuntu系统为例说明
Local time:2020-05-05 14:52:52 CST
Universal time:2020-05-05 06:52:52 UTC
RTC time:2020-05-05 06:52:52
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes         ##如果和远程NTP服务器成功同步,显示为yes
systemd-timesyncd.service active: yes    ##NTP时间同步是否开启,yes表示是,systemd-timesyncd服务为活动也就是开启了NTP时间同步
RTC in local TZ: no
timedatectl 命令显示本地时间、世界时、时区以及系统时钟是否与互联网服务器同步,以及 systemd-timesyncd.service 是处于活动状态还是非活动状态。

Modify time zone method

1. Use the command: tzselect

选择亚洲 Asia
确认之后选择中国(China)
选择北京(Beijing)
选择(yes)

2. Check the time date -R again, it has been changed to Beijing time

insert image description here

3. The output result of simple date, where CST means East Eighth District

insert image description here

The above modification is the system time, which is controlled by the operating system.
There is also a hardware time. Use hwclock --systohc to synchronize the system time to the hardware time.

Hardware Clock and System Clock

(1) 硬件时钟
RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。

(2) 系统时钟
一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。

Hardware Clock Settings

(1) 读取时间
timedatectl //等同于 timedatectl status

(2) 设置时区
timedatectl set-timezone Asia/Shanghai

(3) 是否NTP服务器同步
timedatectl set-ntp yes //yes或者no

(4) 将硬件时钟调整为与本地时钟一致
timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致

注意: 硬件时钟默认使用UTC时间,因为硬件时钟不能保存时区和夏令时调整,修改后就无法从硬件时钟中读取出准确标准时间因此不建议修改。

GMT, UTC, CST, DST time

(1) UTC

The entire earth is divided into twenty-four time zones, and each time zone has its own local time. In the case of international radio communication, for the sake of uniformity, a unified time is used, which is called Universal Coordinated Time (UTC, Universal Time Coordinated).

(2) GMT

Greenwich Mean Time (Greenwich Mean Time) refers to the standard time of the Royal Greenwich Observatory in the suburbs of London, England, because the prime meridian is defined as the longitude passing there. (UTC and GMT time are basically the same, no distinction is made in this article)

(3) CST

China Standard Time

(4) DST

Daylight Saving Time (Daylight Saving Time) means that when the sun rises earlier in summer, the clock is advanced by one hour to advance the use of sunlight. (not used in China)

GMT + 8 = UTC + 8 = CST

Guess you like

Origin blog.csdn.net/weixin_45265547/article/details/131375947