Linux
為什麼“hwclock”命令對本地時間應用正偏移,而“date”命令應用負偏移?
我在使用時區時遇到了一些問題。有人可以向我解釋這些結果嗎?為什麼
hwclock
命令應用本地時間的正偏移量,而date
命令應用負偏移量?$> export TZ=BRA+2 $> date Tue Jan 31 18:22:45 BRA 2017 $> date -u Tue Jan 31 20:22:48 UTC 2017 $> hwclock --systohc $> hwclock -l Tue Jan 31 18:23:04 2017 0.000000 seconds $> hwclock -u Tue Jan 31 16:23:12 2017 0.000000 seconds $> hwclock --systohc --utc $> hwclock -l Tue Jan 31 20:23:31 2017 0.000000 seconds $> hwclock -u Tue Jan 31 18:23:34 2017 0.000000 seconds
我認為您的困惑在於使用
-l
and-u
forhwclock
。請注意,在 hwclock 命令中使用 –utc 或 –localtime 選項並不意味著您以 UTC 或本地時間顯示硬體時鐘時間。
這意味著當您執行時:
hwclock -u
您沒有以 UTC 顯示時間,而是在告訴系統以 UTC 解釋 hwclock,反之亦然
-l
。從手冊頁:
-u, --utc --localtime Indicates that the Hardware Clock is kept in Coordinated Universal Time or local time, respectively. It is your choice whether to keep your clock in UTC or local time, but nothing in the clock tells which you've chosen. So this option is how you give that information to hwclock. If you specify the wrong one of these options (or specify neither and take a wrong default), both setting and querying of the Hardware Clock will be messed up. If you specify neither --utc nor --localtime , the default is whichever was specified the last time hwclock was used to set the clock (i.e. hwclock was successfully run with the --set, --systohc, or --adjust options), as recorded in the adjtime file. If the adjtime file doesn't exist, the default is local time.
(來源)