我在使用时区时遇到一些问题。有人可以向我解释一下这些结果吗?为什么该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
答案1
我认为您的困惑在于 the-l
和-u
for的使用hwclock
。
请注意,在 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.
(来源)