1、查看系统时间
[[email protected] ~]# date
Thu Dec 20 23:25:33 CST 2012
[[email protected] ~]# date +"%Y%m%d %H:%m:%S"
20121220 23:12:54
2、查看硬件时间
系统时钟是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的时钟,这个硬件时钟可以在BIOS中进行设置。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。
[[email protected] ~]# hwclock
Thu 20 Dec 2012 02:57:09 PM CST -0.176702 seconds
[[email protected] ~]# clock
Thu 20 Dec 2012 02:57:14 PM CST -0.575501 seconds
3、修改系统时间
[[email protected] ~]# date
Thu Dec 20 23:27:43 CST 2012
[[email protected] ~]# date -s "20121220 15:28:00"
Thu Dec 20 15:28:00 CST 2012
[[email protected] ~]# date
Thu Dec 20 15:28:03 CST 2012
4、修改硬件时间
[[email protected] ~]# hwclock
Thu 20 Dec 2012 03:30:58 PM CST -0.119534 seconds
[[email protected] ~]# hwclock --set --date="20121220 23:31:00"
[[email protected] ~]# hwclock
Thu 20 Dec 2012 11:31:08 PM CST -0.451844 seconds
5、系统时间与硬件时间之间的同步
系统时间同步到硬件时间:hwclock -w OR hwclock -- systohc
硬件时间同步到系统时间:hwclock -s OR hwclock -- hctosys
[[email protected] ~]# date
Thu Dec 20 15:39:08 CST 2012
[[email protected] ~]# hwclock
Thu 20 Dec 2012 11:36:25 PM CST -0.661838 seconds
[[email protected] ~]# hwclock -w
[[email protected] ~]# hwclock
Thu 20 Dec 2012 03:39:25 PM CST -0.090384 seconds
6、查看当前时区
[[email protected] ~]# date -R
Thu, 20 Dec 2012 15:41:24 +0800
[[email protected] ~]# cat /etc/sysconfig/clock |grep -i zone
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"
7、修改当前时区
方法一、[[email protected] ~]# timeconfig
界面化修改,仅适用于RHEL
方法二、修改/etc/localtime文件,该文件定义了Local Time Zone
[[email protected] ~]# date -R
Thu, 20 Dec 2012 15:46:51 +0800
[[email protected] ~]# mv /etc/localtime /etc/localtime.bak
[[email protected] ~]# cp /usr/share/zoneinfo/America/New_York /etc/localtime
[[email protected] ~]# date -R
Thu, 20 Dec 2012 02:47:40 -0500
[[email protected] ~]# cat /etc/sysconfig/clock |grep -i zone
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"
修改成功,但/etc/sysconfig/clock文件中的timezone未变。
方法三、设置TZ环境变量
[[email protected] ~]# date -R
Thu, 20 Dec 2012 02:53:15 -0500
[[email protected] ~]# echo "export TZ=Asia/Shanghai" >>/etc/profile
[[email protected] ~]# cat /etc/profile |grep TZ
export TZ=Asia/Shanghai
[[email protected] ~]# source /etc/profile
[[email protected] ~]# date -R
Thu, 20 Dec 2012 15:54:47 +0800
$TZ环境变量的优先级要比/etc/localtime要高,并且在设置该全局环境变量后,即使使用timeconfig来修改也一样无法改变时区。
8、查看当前相应时区时间
查看-5区当前时间
[[email protected] ~]# zdump GMT-5
GMT-5 Thu Dec 20 12:59:13 2012 GMT
附相关缩写含义
CST:CST同时可以代表如下 4 个不同的时区:
Central Standard Time (USA) UT-6:00
Central Standard Time (Australia) UT+9:30
China Standard Time UT+8:00
Cuba Standard Time UT-4:00
可见,CST可以同时表示美国,澳大利亚,中国,古巴四个国家的标准时间。
EDT - Eastern Daylight Time 东部夏令时间
CDT - Central Daylight Time 中部夏令时间
UTC:协调世界时,又称世界标准时间或世界协调时间,简称UTC,从英文“Coordinated Universal Time” 称为世界统一时间。