1、查看系統時間
[root@test3 ~]# date
Thu Dec 20 23:25:33 CST 2012
[root@test3 ~]# date +"%Y%m%d %H:%m:%S"
20121220 23:12:54
2、查看硬件時間
系統時鐘是指當前Linux Kernel中的時鐘,而硬件時鐘則是主板上由電池供電的時鐘,這個硬件時鐘可以在BIOS中進行設置。當Linux啓動時,硬件時鐘會去讀取系統時鐘的設置,然後系統時鐘就會獨立於硬件運作。
[root@test3 ~]# hwclock
Thu 20 Dec 2012 02:57:09 PM CST -0.176702 seconds
[root@test3 ~]# clock
Thu 20 Dec 2012 02:57:14 PM CST -0.575501 seconds
3、修改系統時間
[root@test3 ~]# date
Thu Dec 20 23:27:43 CST 2012
[root@test3 ~]# date -s "20121220 15:28:00"
Thu Dec 20 15:28:00 CST 2012
[root@test3 ~]# date
Thu Dec 20 15:28:03 CST 2012
4、修改硬件時間
[root@test3 ~]# hwclock
Thu 20 Dec 2012 03:30:58 PM CST -0.119534 seconds
[root@test3 ~]# hwclock --set --date="20121220 23:31:00"
[root@test3 ~]# hwclock
Thu 20 Dec 2012 11:31:08 PM CST -0.451844 seconds
5、系統時間與硬件時間之間的同步
系統時間同步到硬件時間:hwclock -w OR hwclock -- systohc
硬件時間同步到系統時間:hwclock -s OR hwclock -- hctosys
[root@test3 ~]# date
Thu Dec 20 15:39:08 CST 2012
[root@test3 ~]# hwclock
Thu 20 Dec 2012 11:36:25 PM CST -0.661838 seconds
[root@test3 ~]# hwclock -w
[root@test3 ~]# hwclock
Thu 20 Dec 2012 03:39:25 PM CST -0.090384 seconds
6、查看當前時區
[root@test3 ~]# date -R
Thu, 20 Dec 2012 15:41:24 +0800
[root@test3 ~]# 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、修改當前時區
方法一、[root@test3 ~]# timeconfig
界面化修改,僅適用於RHEL
方法二、修改/etc/localtime文件,該文件定義了Local Time Zone
[root@test3 ~]# date -R
Thu, 20 Dec 2012 15:46:51 +0800
[root@test3 ~]# mv /etc/localtime /etc/localtime.bak
[root@test3 ~]# cp /usr/share/zoneinfo/America/New_York /etc/localtime
[root@test3 ~]# date -R
Thu, 20 Dec 2012 02:47:40 -0500
[root@test3 ~]# 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環境變量
[root@test3 ~]# date -R
Thu, 20 Dec 2012 02:53:15 -0500
[root@test3 ~]# echo "export TZ=Asia/Shanghai" >>/etc/profile
[root@test3 ~]# cat /etc/profile |grep TZ
export TZ=Asia/Shanghai
[root@test3 ~]# source /etc/profile
[root@test3 ~]# date -R
Thu, 20 Dec 2012 15:54:47 +0800
$TZ環境變量的優先級要比/etc/localtime要高,並且在設置該全局環境變量後,即使使用timeconfig來修改也一樣無法改變時區。
8、查看當前相應時區時間
查看-5區當前時間
[root@test3 ~]# zdump GMT-5
GMT-5 Thu Dec 20 12:59:13 2012 GMT
9、suse時間與時區的修改
suse時間的修改與redhat linux相同,具體方法參照以上操作;
suse時區的交互式界面修改方法yast---system---Date and Time找到合適的時區,確定進行修改。
10、附相關縮寫含義
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” 稱爲世界統一時間。