時間以及時區設定
by:授客 QQ:1033553122
1.首先确認使用utc還是local time.
UTC(Universal Time Coordinated)=GMT(Greenwich Mean Time),Local time 本地時間,
傳統的POSIX計算機(Solaris,bsd,unix)使用UTC格式,linux可以處理UTC時間和蹩腳的Windows所使用的local time
到底是使用UTC還是local time可以這樣來确定:
如果機器上同時安裝有Linux和Windows,建議使用Local time
如果機器上隻安裝有Linux,建議使用utc
2.确定後編輯/etc/sysconfig/clock
設定UTC=0或UTC=FALSE->硬體時鐘為local time; UTC=1或UTC=TRUE->硬體時鐘UTC(GMT),ARC=0或ARC=FALSE,->如果是在Alpha機器上,則設定為TRUE,否則FALSE 。
注:把硬體時鐘設定為 UTC 的好處就是他能自動設定夏時制,缺點是在安裝有多重作業系統啟動的機器上,在另外的作業系統上時鐘會錯誤。
Linux 啟動時,其中的一個腳本(/etc/rc.d/rc.sysinit)會運作/sbin/hwclock 程式,把目前的硬體時鐘複制為系統時間。以後修改時間通過修改系統時間實作。為了保持系統時間與CMOS時間的一緻性,Linux每隔一段時間會将系統時間寫入CMOS。hwclock假定硬體時鐘已經設定為本地時鐘,除非帶有utc參數。腳本檔案會讀取 /etc/sysconfig/clock 檔案的設定,是以我們不需要修改腳本,直接修改這個配置檔案就可以了
修改/etc/sysconfig/clock檔案,添加如下内容:
ZONE="Asia/Shanghai"
UTC=false
ARC=false
3.使用cat
/etc/sysconfig/clock檢視目前時區
[root@localhost
laiyu]# cat /etc/sysconfig/clock
# The time zone
of the system is defined by the contents of
/etc/localtime.
# This file is
only for evaluation by system-config-date, do not rely on
its
# contents
elsewhere.
UTC=FALSE
ARC=FALSE
4.使用tzselect設定時區
laiyu]# 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
7) Australia
8) Europe
9) Indian
10) Pacific
11) none - I
want to specify the time zone using the Posix TZ format.
#?
5[Enter]
country.
1)
Afghanistan
18) Israel
35) Palestine
2) Armenia
19) Japan
36) Philippines
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) Taiwan
10)
Cyprus
27) Lebanon
44) Tajikistan
11) East
Timor
28) Macau
45) Thailand
12)
Georgia
29) Malaysia
46) Turkmenistan
13) Hong
Kong
30) Mongolia
47) United Arab Emirates
14)
India
31) Myanmar (Burma)
48) Uzbekistan
15)
Indonesia
32) Nepal
49) Vietnam
16)
Iran
33) Oman
50) Yemen
17)
Iraq
34)
Pakistan
9[Enter]
Please select
one of the following time zone regions.
1) east China -
Beijing, Guangdong, Shanghai, etc.
2) Heilongjiang
(except Mohe), Jilin
3) central
China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc.
4) most of
Tibet & Xinjiang
5) west Tibet
& Xinjiang
1[Enter]
The following
information has been given:
China
east China - Beijing, Guangdong, Shanghai, etc.
Therefore
TZ='Asia/Shanghai' will be used.
Local time is
now:
2012年
11月
25日星期日
22:40:32
CST.
Universal Time
is now:
14:40:32
UTC.
Is the above
information OK?
1)
Yes
2)
No
You can make
this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file
'.profile' in your home directory; then log out and log in
again.
Here is that TZ
value again, this time on standard output so that you
can use the
/usr/bin/tzselect command in shell scripts:
Asia/Shanghai
5.複制相應的時區檔案,替換系統預設時區
laiyu]# cp /usr/share/zoneinfo/Asia/Shanghai
/etc/localtime
cp:
"/usr/share/zoneinfo/Asia/Shanghai"
與"/etc/localtime"
為同一檔案
注:cp
/usr/share/zoneinfo/主時區/次時區
時鐘設定檔案為:/etc/localtime,實際上這個檔案是/usr/share/zoneinfo目錄下對應檔案的符号連接配接
6.設定時間與internet同步
laiyu]# ntpdate asia.pool.ntp.org
25 Nov 22:33:50
ntpdate[3210]: adjust time server 220.130.158.71 offset -0.060016
sec
注:設定系統時間也可以用date或date
-s指令
附:the NTP socket is
in use, exiting的解決辦法,如下
25 Nov 22:28:18
ntpdate[3176]: the NTP socket is in use, exiting
laiyu]# service ntpd stop
Shutting down
ntpd:
[
OK
]
laiyu]# date
22:33:58
CST
7.将目前時間寫入BIOS永久生效(避免重新開機後失效),讓系統時間與硬體時鐘同步
laiyu]# hwclock
2012年11月25日星期日
22時44分22秒
-0.032355 seconds
或者
laiyu]# clock -w
注:clock指令除了支援x86硬體體系外,還支援Alpha硬體體系。
8.檢視Bois(cmos)時間(用
#hwclock
-r
laiyu]# hwclock -r
22時49分46秒
-0.813294 seconds
laiyu]# hwclock --show
laiyu]# clock --show
作者:授客
QQ:1033553122
全國軟體測試QQ交流群:7156436
Git位址:https://gitee.com/ishouke
友情提示:限于時間倉促,文中可能存在錯誤,歡迎指正、評論!
作者五行缺錢,如果覺得文章對您有幫助,請掃描下邊的二維碼打賞作者,金額随意,您的支援将是我繼續創作的源動力,打賞後如有任何疑問,請聯系我!!!
微信打賞
支付寶打賞 全國軟體測試交流QQ群
