2013年4月24日 星期三

Linux - 設定TimeZone


轉載於: http://linux-guys.blogspot.tw/2011/02/linux-timezone.html


第一種
查看目前時區
[root@darwin-test ~]# date
Wed Feb  9 05:20:22 EST 2011

[root@darwin-test ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="America/New_York"   //目前是New York時區
UTC=true
ARC=false

暫時設定台灣時區
[root@darwin-test ~]# export TZ='Asia/Taipei'
[root@darwin-test ~]# date
Wed Feb  9 18:22:24 CST 2011

永久設定時區
[root@darwin-test ~]# system-config-date
[root@darwin-test ~]# cat /etc/sysconfig/clock
# 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/Taipei"
UTC=true
ARC=false

[root@darwin-test ~]# date
Wed Feb  9 18:26:16 CST 2011

另一作法-永久設定時區
編輯家目錄.profile or $HOME/.bash_profile
#vi $HOME/.profile
內容如下
export TZ='Asia/Taipei'

另一命令可供參考
[root@darwin-test ~]# 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
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
#? 43
The following information has been given:
        Taiwan
Therefore TZ='Asia/Taipei' will be used.
Local time is now:      Wed Feb  9 18:21:13 CST 2011.
Universal Time is now:  Wed Feb  9 10:21:13 UTC 2011.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
        TZ='Asia/Taipei'; export TZto 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/Taipei

現在要做的事情就是按照提示,把TZ='Asia/Taipei'; export TZ   添加到.profile中(bash對應加到.bash_profile)。


tzselect命令用於選擇時區。要注意的是tzselect只是幫我們把選擇的時區顯示出來,並不會實際生效,也就是說它僅僅告訴我們怎麼樣去設置環境變量TZ。

如果你要永久更改時區,按照tzselect命令提示的信息,在.profile或者/etc/profile中設置正確的TZ環境變量並導出。還有另外一種更改時區的方法就是直接更改系統配置文件/etc/sysconfig/clock,然後修改符號鏈接/etc/locatime對應的文件,詳見示例三。

第二種

示例三 通過更改配置文件來修改時區
[root@new55 ~]# cat /etc/sysconfig/clock
# 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"
UTC=true
ARC=false
[root@new55 ~]#
修改linux系統時區
    1) 可修改/etc/sysconfig/clock
        ZONE=Asia/Shanghai ( 查/usr/share/zoneinfo 下面的文件。 )
        UTC=false ( 硬件時鐘是否為UTC 或者說GMT 時鐘。 )
        ARC=false (如果是在Alpha 機器上,則設置為true 。 )
    (把硬件時鐘設置為UTC 的好處就是他能自動設置夏時制,缺點是,在安裝有多重操作系統啟動的機器上,在另外的操作系統上時鐘會錯誤。 )
    2) rm /etc/localtime
        Zhy: 這個文件是個符號鏈接?如果是在系統安裝時就設置好的話,就是個普通文件。
    3) 以上海為例:
        ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime



第三種

變更 Linux 系統預設時區(timezone)
1. 使用 root 帳號登入終端機
2. 執行 date 指令,此時會出現類似 Wed Jan 27 14:11:29 CST 2010 的訊息,其中 CST 就是目前系統預設時區
3. 切換到 /usr/share/zoneinfo 目錄,其中有所有時區(timezone)的列表, Taipei 時區在 Asia 下
4.  執行 mv /etc/localtime  /etc/localtime-old 備份目前設定
5.  執行 ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime 將欲使用的時區 softlink 到 /etc/localtime
6.  修改 /etc/sysconfig/clock 檔案內容,改為 ZONE="Asia/Taipei"
7.  執行 /sbin/hwclock --systohc 同步硬體時鐘





1 則留言:

ohfish 提到...

export TZ="UTC-08:00"

[GPO] 在Microsoft Active Directory (AD) 網域環境,新增Microsoft Edge群組原則管理

[GPO]  在 Microsoft Active Directory (AD) 網域環境, 新增Microsoft Edge群組原則管理 在還沒有被微軟強迫使用Edge前,對於一些老舊的網站,還可以使用IE。 因此在公司環境,之前有為IE和google chrome,寫入配合的...