日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

Linux 时间及时区设置

發布時間:2023/12/19 综合教程 25 生活家
生活随笔 收集整理的這篇文章主要介紹了 Linux 时间及时区设置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

時間以及時區設置

by:授客 QQ1033553122

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.

ZONE="Asia/Shanghai"

UTC=FALSE

ARC=FALSE

4.使用tzselect設置時區

[root@localhost
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
Ocean

7) Australia

8) Europe

9) Indian
Ocean

10) Pacific
Ocean

11) none - I
want to specify the time zone using the Posix TZ format.

#?
5[Enter]

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) 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:
2012年
11月
25日星期日
14:40:32
UTC.

Is the above
information OK?

1)
Yes

2)
No

#?
1[Enter]

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.復制相應的時區文件,替換系統默認時區

[root@localhost
laiyu]# cp /usr/share/zoneinfo/Asia/Shanghai
/etc/localtime

cp:
"/usr/share/zoneinfo/Asia/Shanghai"
與"/etc/localtime"

為同一文件


注:cp
/usr/share/zoneinfo/主時區/次時區
/etc/localtime


時鐘設置文件為:/etc/localtime,實際上這個文件是/usr/share/zoneinfo目錄下對應文件的符號連接

6.設置時間與internet同步

[root@localhost
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的解決辦法,如下

[root@localhost
laiyu]# ntpdate asia.pool.ntp.org

25 Nov 22:28:18
ntpdate[3176]: the NTP socket is in use, exiting

[root@localhost
laiyu]# service ntpd stop

Shutting down
ntpd:
[
OK
]

[root@localhost
laiyu]# ntpdate asia.pool.ntp.org

25 Nov 22:33:50
ntpdate[3210]: adjust time server 220.130.158.71 offset -0.060016
sec

[root@localhost
laiyu]# date

2012年
11月
25日星期日
22:33:58
CST

7.將當前時間寫入BIOS永久生效(避免重啟后失效),讓系統時間與硬件時鐘同步

[root@localhost
laiyu]# hwclock

2012年11月25日星期日
22時44分22秒
-0.032355 seconds


或者

[root@localhost
laiyu]# clock -w


注:clock命令除了支持x86硬件體系外,還支持Alpha硬件體系。

8.查看Boiscmos)時間(用
#hwclock
-r

[root@localhost
laiyu]# hwclock -r

2012年11月25日星期日
22時49分46秒
-0.813294 seconds


或者

[root@localhost
laiyu]# hwclock --show


或者

[root@localhost
laiyu]# clock --show

總結

以上是生活随笔為你收集整理的Linux 时间及时区设置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。