注意:
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
北京时间,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. seconds # hwclock -u Wed 14 Apr 2021 06:16:12 PM JST -0. seconds # hwclock --localtime Wed 14 Apr 2021 09:16:16 AM JST -0. 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
注意:按照提示操作(如下),时区修改只会对本用户环境生效
参考资料:
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/233342.html原文链接:https://javaforall.net