CST:中國標準時間(China Standard Time),這個解釋可能是針對RedHat Linux。
UTC:協調世界時,又稱世界標準時間,簡稱UTC,從英文國際時間/法文協調時間“Universal Time/Temps Cordonné”而來。中國大陸、香港、澳門、臺灣、蒙古國、新加坡、馬來西亞、菲律賓、澳洲西部的時間與UTC的時差均爲+8,也就是UTC+8。
GMT:格林尼治標準時間(舊譯格林威治平均時間或格林威治標準時間;英語:Greenwich Mean Time,GMT)是指位於英國倫敦郊區的皇家格林尼治天文臺的標準時間,因爲本初子午線被定義在通過那裏的經線。
設置完系統時間後,還需要同步到硬件時鐘上。
1、date
linux自帶的命令,可以顯示和修改linux系統的當前時間。
如果localtime設置爲Asia/Shanghai,date顯示東八區時間,date -u顯示UTC時間,比CST時間慢8個小時。
用法如下:
Usage: date [OPTIONS] [+FMT] [TIME]
Display time (using +FMT), or set time
[-s,--set] TIME Set time to TIME
-u,--utc Work in UTC (don't convert to local time)
-R,--rfc-2822 Output RFC-2822 compliant date string
-I[SPEC] Output ISO-8601 compliant date string
SPEC='date' (default) for date only,
'hours', 'minutes', or 'seconds' for date and
time to the indicated precision
-r,--reference FILE Display last modification time of FILE
-d,--date TIME Display TIME, not 'now'
-D FMT Use FMT for -d TIME conversion
Recognized TIME formats:
hh:mm[:ss]
[YYYY.]MM.DD-hh:mm[:ss]
YYYY-MM-DD hh:mm[:ss]
[[[[[YY]YY]MM]DD]hh]mm[.ss]
'date TIME' form accepts MMDDhhmm[[YY]YY][.ss] instead
date -s 2016-10-10 設置年月日
date -s 11.11.11 設置時分秒
2、系統時間和硬件時間
date這裏說的是系統時間,是linux由操作系統維護的。
在系統啓動時,Linux操作系統將時間從CMOS中讀到系統時間變量中,以後修改時間通過修改系統時間實現。爲了保持系統時間與CMOS時間的一致性,Linux每隔一段時間會將系統時間寫入CMOS。由於該同步是每隔一段時間(大約是11分鐘,未經驗證)進行的,在我們執行date -s後,如果馬上重起機器,修改時間就有可能沒有被寫入CMOS。
如果要確保修改生效可以執行hwclock –w命令,強制把系統時間寫入CMOS。
hwclock -w之後,下次啓動這個寫入的時間會作爲UTC時間,date -u顯示該時間,date顯示CST東八區時間,該時間+8h。
hwclock命令用法:
Usage: hwclock [-r|--show] [-s|--hctosys] [-w|--systohc] [-t|--systz] [-l|--localtime] [-u|--utc] [-f|--rtc FILE]
Query and set hardware clock (RTC)
-r Show hardware clock time
-s Set system time from hardware clock
-w Set hardware clock from system time
-t Set in-kernel timezone, correct system time
if hardware clock is in local time
-u Assume hardware clock is kept in UTC
-l Assume hardware clock is kept in local time
-f FILE Use specified device (e.g. /dev/rtc2)