GMT:Greenwich Mean Time,即格林尼治标准时间。GMT 以地球自转为基础,但由于地球自转不均匀,导致 GMT 不精确。
UTC:Universal Time Coordinated,即协调世界时,UTC 是以原子时秒长为基础,在时刻上尽量接近于 GMT 的一种时间计量系统。
RTC:Real-Time Clock,即实时时钟,在计算机领域作为硬件时钟的简称。
硬件时间:保存在主板BIOS中,信息比较少没时区、夏令时的概念。
系统时间:系统开机时读取硬件时间作为系统的时间,系统关机时再将系统时间写回RTC又系统时间,拥有时区、夏令时等信息。
注意:
1.date命令操作系统时间,hwclock操作硬件时钟,所以date 修改时间后,最好用hwclock 同步一下,以免系统非正常关机造成时间不同步。
2.hwclock 查看的时间并不一定就是RTC的时间,使用hwclock –localtime 查看才是寄存器中的值。
3.系统关闭时会同步系统时间到硬件时钟,系统启动时会从硬件时钟读取时间更新到系统,当主机运行很久都没有重启时就有可能发生系统时间与硬件时间不一样的情况。这2个步骤都要根据 /etc/sysconfig/clock 文件中UTC的参数来设置时区转换。
@ hwclock命令
1、查看硬件时间 hwclock
2、将系统时间同步到硬件时间 hwclock -w
3、将硬件时间同步到系统时间 hwclock -s
4、设定硬件时钟 hwclock -set --date=<日期与时间>
hwclock --set --date 20210412
hwclock --set --date 10:01:10
hwclock --set --date "20210412 20:20:00"
hwclock --set --date "2021-04-12 10:01:10"
北京时间20210414,17:16
# uptime
18:23:13 up 147 days, 5:04, 1 user, load average: 0.01, 0.04, 0.00
#
# hwclock
Wed 14 Apr 2021 06:16:09 PM JST -0.734618 seconds
# hwclock -u
Wed 14 Apr 2021 06:16:12 PM JST -0.234563 seconds
# hwclock --localtime
Wed 14 Apr 2021 09:16:16 AM JST -0.312695 seconds
# cat /etc/sysconfig/clock
ZONE="Asia/Tokyo"
@ 修改时区
tzselect
[root@xxx bin]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 6
Please select a country.
1) Bermuda
2) Cape Verde
3) Falkland Islands
4) Faroe Islands
5) Iceland
6) Portugal
7) South Georgia & the South Sandwich Islands
8) Spain
9) St Helena
#? 5
The following information has been given:
Iceland
Therefore TZ='Atlantic/Reykjavik' will be used.
Local time is now: Fri Apr 9 10:10:53 GMT 2021.
Universal Time is now: Fri Apr 9 10:10:53 UTC 2021.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
TZ='Atlantic/Reykjavik'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Atlantic/Reykjavik
将时区信息拷贝,并覆盖原来的时区信息
cp /usr/share/zoneinfo/Atlantic/Reykjavik /etc/localtime
[root@xxx bin]# date
Fri Apr 9 10:26:44 GMT 2021
注意:按照提示操作(如下),时区修改只会对本用户环境生效
You can make this change permanent for yourself by appending the line
TZ='Atlantic/Reykjavik'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
参考资料:
linux时间管理与配置date与hwclock命令 https://www.cnblogs.com/pipci/p/12828780.html
Linux中date时间和hwclock时间不一致解决方案 https://www.jianshu.com/p/304dedfef15d