代码改变世界

LINUX下的时间与时区的设置

2014-02-22 16:45  梁小白  阅读(1251)  评论(0编辑  收藏  举报

 

在RHEL下,如果只装英文版系统,设置好时区以后(上海时间,UTC)

在命令行下用date命令查看,总是与实际的北京时间差8小时,其实硬件时间都是准确的。会带来视觉不便。

今天下决心解决此问题,不过也没费时,有人写好了。

http://www.opsers.org/linux-home/base/talk-about-rhel6-system-issues-an-eight-hour-time-difference.html

方法很简单:

复制正确时区文件

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 

date -R

显示当前系统时间

date -s "将上面显示的时间复制过来"

hwclock -w --localtime 设置硬件时间

hwclock -s --localtime #可将此句加入/etc/rc.local

让硬件时间使用本地时间即可。

[root@yufei ~]# hwclock --help
hwclock - query and set the hardware clock (RTC)

Usage: hwclock [function] [options...]
这里需要大家特别注意:先是函数后是参数,只用其中一个是没有用的,这是解决问题的关键

Functions:
  -r | --show         read hardware clock and print result #读取硬件(BIOS)时间,并显示出来
  -s | --hctosys      set the system time from the hardware clock #把目前系统时间调整为硬件时间
  -w | --systohc      set the hardware clock to the current system time #把硬件时间调整为目前系统的时间
       --systz        set the system time based on the current timezone #把系统时间设置为当时时区的时间

Options:
  -u | --utc          the hardware clock is kept in UTC #设置硬件为的UTC时间
       --localtime    the hardware clock is kept in local time #设置硬件为本地时间

想深入了解一下?:
http://kerrigan.sinaapp.com/post-6.html