檢視指令
date
centos設定目前系統時間指令
[root@t1 data]# date --set "03/19/16 11:30"
sat mar 19 11:30:00 pdt 2016
linux時鐘分為系統時鐘(system clock)和硬體(real time clock,簡稱rtc)時鐘。系統時鐘是指目前linux kernel中的時鐘,而硬體時鐘則是主機闆上由電池供電的時鐘,這個硬體時鐘可以在bios中進行設定。當linux啟動時,硬體時鐘會去讀取系統時鐘的設定,然後系統時鐘就會獨立于硬體運作。
linux中的所有指令(包括函數)都是采用的系統時鐘設定。在linux中,用于時鐘檢視和設定的指令主要有date、hwclock和clock。其中,clock和hwclock用法相近,隻用一個就行,隻不過clock指令除了支援x86硬體體系外,還支援alpha硬體體系。
1、date
檢視系統時間
設定系統時間
2、hwclock/clock
檢視硬體時間
# hwclock --show
或者# clock --show
設定硬體時間
# hwclock --set --date="07/07/06 10:19" (月/日/年 時:分:秒)
或者# clock --set --date="07/07/06 10:19" (月/日/年 時:分:秒)
3、硬體時間和系統時間的同步
按照前面的說法,重新啟動系統,硬體時間會讀取系統時間,實作同步,但是在不重新啟動的時候,需要用hwclock或clock指令實作同步。
硬體時鐘與系統時鐘同步:# hwclock --hctosys(hc代表硬體時間,sys代表系統時間)或者# clock --hctosys
系統時鐘和硬體時鐘同步:# hwclock --systohc或者# clock --systohc
4、時區的設定
# tzselect
please identify a location so that time zone rules can be set correctly.please select a continent or ocean. 1) africa 2) americas 3) antarctica 4) arctic ocean 5) asia 6) atlantic ocean 7) australia 8) europe 9) indian ocean10) pacific ocean11) none - i want
to specify the time zone using the posix tz format.#? 輸入5,亞洲
please select a country. 1) afghanistan 18) israel 35) palestine 2) armenia 19) japan 36) philippines 3) azerbaijan 20) jordan 37) qatar 4) bahrain 21) kazakhstan 38) russia 5) bangladesh 22) korea (north) 39) saudi arabia 6) bhutan 23) korea (south) 40) singapore
7) brunei 24) kuwait 41) sri lanka 8) cambodia 25) kyrgyzstan 42) syria 9) china 26) laos 43) taiwan10) cyprus 27) lebanon 44) tajikistan11) east timor 28) macau 45) thailand12) georgia 29) malaysia 46) turkmenistan13) hong kong 30) mongolia 47) united arab
emirates14) india 31) myanmar (burma) 48) uzbekistan15) indonesia 32) nepal 49) vietnam16) iran 33) oman 50) yemen17) iraq 34) pakistan#? 輸入9,中國
please select one of the following time zone regions.1) east china - beijing, guangdong, shanghai, etc.2) heilongjiang3) central china - gansu, guizhou, sichuan, yunnan, etc.4) tibet & most of xinjiang uyghur5) southwest xinjiang uyghur#? 輸入1,中原標準時間
the following information has been given:
china east china - beijing, guangdong, shanghai, etc.
therefore tz="asia/shanghai" will be used.local time is now: fri jul 7 10:32:18 cst 2006.universal time is now: fri jul 7 02:32:18 utc 2006.is the above information ok?1) yes2) no#? 輸入1,确認
如果不用tzselect指令,可以修改檔案變更時區。
# vi /etc/sysconfig/clock zone=asia/shanghai(查/usr/share/zoneinfo下面的檔案) utc=false arc=false
# rm /etc/localtime
# ln -sf /usr/share/zoneinfo/asia/shanghai /etc/localtime
重新啟動即可。
贈送:
<a target="_blank" href="http://www.t086.com/article/4386">linux怎樣修改系統時間</a>