CentOS下如何设置时区

CentOS下如何设置时区
先说结论:
在CentOS里,修改时区有几个途径,它们似乎各不相干:
方法一图形化工具修改,实际上是修改 /etc/sysconfig/clock
方法二对 /etc/localtime 建立软链接
方法三用保留的前次的 /etc/localtime备份,恢复到特定的时区
首先,需要指出一点, /etc/localtime 本身是一个不可读的文件,直接看只能看到乱码
但是可以用 zdump命令来看:
[root@fullcent ~]# zdump -v /etc/localtime
/etc/localtime  -9223372036854775808 = NULL
/etc/localtime  -9223372036854689408 = NULL
/
etc/localtime  Sat Dec 31 15:54:07 1927 UTC = Sat Dec 31 23:59:59 1927 CST isdst=0 gmtoff=29152 /etc/localtime  Sat Dec 31 15:54:08 1927 UTC = Sat Dec 31 23:54:08 1927 CST isdst=0 gmtoff=28800 /etc/localtime  Sun Jun  2 15:59:59 1940 UTC = Sun Jun  2 23:59:59 1940 CST isdst=0 gmtoff=28800 /etc/localtime  Sun Jun  2 16:00:00 1940 UTC = Mon Jun  3 01:00:00 1940 CDT isdst=1 gmtoff=32400 /etc/localtime  Mon Sep 30 14:59:59 1940 UTC = Mon Sep 30 23:59:59 1940 CDT isdst=1 gmtoff=32400 /etc/localtime  Mon Sep 30 15:00:00 1940 UTC = Mon Sep 30 23:00:00 1940 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Mar 15 15:59:59 1941 UTC = Sat Mar 15 23:59:59 1941 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Mar 15 16:00:00 1941 UTC = Sun Mar 16 01:00:00 1941 CDT isdst=1 gmtoff=32400 /etc/localtime  Tue Sep 30 14:59:59 1941 UTC = Tue Sep 30 23:59:59 1941 CDT isdst=1 gmtoff=32400 /etc/localtime  Tue Sep 30 15:00:00 1941 UTC = Tue Sep 30 23:00:00 1941 CST isdst=0 gmtoff=28800 /etc/localtime  Sat May  3 15:59:59 1986 UTC = Sat May  3 23:59:59 1986 CST isdst=0 gmtoff=28800 /etc/localtime  Sat May  3 16:00:00 1986 UTC = Sun May  4 01:00:00 1986 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 13 14:59:59 1986 UTC = Sat Sep 13 23:59:59 1986 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 13 15:00:00 1986 UTC = Sat Sep 13 23:00:00 1986 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 11 15:59:59 1987 UTC = Sat Apr 11 23:59:59 1987 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 11 16:00:00 1987 UTC = Sun Apr 12 01:00:00 1987 CDT isdst=1 gmtoff=3240
0 /etc/localtime  Sat Sep 12 14:59:59 1987 UTC = Sat Sep 12 23:59:59 1987 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 12 15:00:00 1987 UTC = Sat Sep 12 23:00:00 1987 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr  9 15:59:59 1988 UTC = Sat Apr  9 23:59:59 1988 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr  9 16:00:00 1988 UTC = Sun Apr 10 01:00:00 1988 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 10 14:59:59 1988 UTC = Sat Sep 10 23:59:59 1988 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 10 15:00:00 1988 UTC = Sat Sep 10 23:00:00 1988 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 15 15:59:59 1989 UTC = Sat Apr 15 23:59:59 1989 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 15 16:00:00 1989 UTC = Sun Apr 16 01:00:00 1989 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 16 14:59:59 1989 UTC = Sat Sep 16 23:59:59 1989 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 16 15:00:00 1989 UTC = Sat Sep 16 23:00:00 1989 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 14 15:59:59 1990 UTC = Sat Apr 14 23:59:59 1990 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 14 16:00:00 1990 UTC = Sun Apr 15 01:00:00 1990 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 15 14:59:59 1990 UTC = Sat Sep 15 23:59:59 1990 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 15 15:00:00 1990 UTC = Sat Sep 15 23:00:00 1990 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 13 15:59:59 1991 UTC = Sat Apr 13 23:59:59 1991 CST isdst=0 gmtoff=28800 /etc/localtime  Sat Apr 13 16:00:00 1991 UTC = Sun Apr 14 01:00:00 1991 CDT isdst=1 gmtoff=32400 /etc/localtim
e  Sat Sep 14 14:59:59 1991 UTC = Sat Sep 14 23:59:59 1991 CDT isdst=1 gmtoff=32400 /etc/localtime  Sat Sep 14 15:00:00 1991 UTC = Sat Sep 14 23:00:00 1991 CST isdst=0 gmtoff=28800 /etc/localtime  9223372036854689407 = NULL
tz15
/etc/localtime  9223372036854775807 = NULL
[root@fullcent ~]# ls -lrt /etc/localtime
-rw-r--r-- 1 root root 405 Mar  8 17:42 /etc/localtime
[root@fullcent ~]# file /etc/localtime
/etc/localtime: timezone data
[root@fullcent ~]#
先来查看当前的时区
发现目前是8时区,也就是北京时间或者上海时间
[root@fullcent ~]# date -R
Wed, 13 Mar 2013 14:24:36 +0800
[root@fullcent ~]# date
Wed Mar 13 14:24:38 CST 2013
[root@fullcent ~]#
用 tzselect 查看时区信息:
[root@fullcent ~]# 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
#? 23
The following information has been given:
Korea (South)
Therefore TZ='Asia/Seoul' will be used.
Local time is now:      Wed Mar 13 15:26:56 KST 2013.
Universal Time is now:  Wed Mar 13 06:26:56 UTC 2013.
Is the above information OK?
1) Yes
2) No
#? Yes
Please enter 1 for Yes, or 2 for No.
#? 1
You can make this change permanent for yourself by appending the line
TZ='Asia/Seoul'; 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/Seoul
[root@fullcent ~]#
吸收式制冷机组
[root@fullcent ~]# date
Wed Mar 13 14:28:01 CST 2013
[root@fullcent ~]#
tzselect 只是起到一个展示的作用!!!
现在修改  /etc/localtime,把它指向/usr/share/zoneinfo/下某个时区文件的软链接。
并做好备份!
[root@fullcent ~]# cp /etc/localtime /etc/localtime.bak
[root@fullcent ~]# ls -lrt /etc/localtime*
-rw-r--r-- 1 root root 405 Mar  8 17:42 /etc/localtime
-rw-r--r-- 1 root root 405 Mar 13 14:37 /etc/localtime.bak
[root@fullcent ~]# ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
[root@fullcent ~]# ls -ls /etc/localtime
0 lrwxrwxrwx 1 root root 30 Mar 13 15:41 /etc/localtime -> /usr/share/zoneinfo/Asia/Seoul [root@fullcent ~]#
此时再看,时区更改已经生效了:
[root@fullcent ~]# date -R
Wed, 13 Mar 2013 15:43:26 +0900
[root@fullcent ~]# date
Wed Mar 13 15:43:29 KST 2013
[root@fullcent ~]#
看/etc/sysconfig/clock,还没有反应过来
[root@fullcent ~]# 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@fullcent ~]#
在Gnome桌面上的 System->Administratrion->Date and Time 看到的结果仍然如此:
即便是重新启动后,再次看到的情形仍然如此:
[root@fullcent ~]# 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@fullcent ~]# date -R
Wed, 13 Mar 2013 15:55:11 +0900
[root@fullcent ~]# date
Wed Mar 13 15:55:14 KST 2013
[root@fullcent ~]#
也就是说 /etc/localtime 与 /etc/sysconfig/clock 产生了不一致
还是手工改动了吧:
防盗井盖
[root@fullcent ~]# 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/Seoul"
UTC=true
ARC=false
[root@fullcent ~]#
改完了文件后,再次看看,图形化工具中的时区也改为 Seoul了。
考虑回复最初的 /etc/localtime(就是我没有改动过的 localtime文件,当时的时间是8时区) [root@fullcent ~]# date -R
Wed, 13 Mar 2013 16:05:14 +0900
[root@fullcent ~]#
[root@fullcent ~]# ls -lsrt /etc/localtime*
4 -rw-r--r-- 1 root root 40
5 Mar 13 15:37 /etc/localtime.bak
0 lrwxrwxrwx 1 root root  30 Mar 13 15:41 /etc/localtime -> /usr/share/zoneinfo/Asia/Seoul
[root@fullcent ~]# rm -rf /etc/localtime
[root@fullcent ~]# ls -lsrt /etc/localtime*
4 -rw-r--r-- 1 root root 40
5 Mar 13 06:37 /etc/localtime.bak
[root@fullcent ~]# cp /etc/localtime.bak /etc/localtime
[root@fullcent ~]#
成功回复到了原有时区!
[root@fullcent ~]# date -R
Wed, 13 Mar 2013 15:10:11 +0800
[root@fullcent ~]# date
Wed Mar 13 15:10:14 CST 2013
[root@fullcent ~]#
但是此时,/etc/sysconfig/clock确实没有恢复回来,即便重新启动也不行:[root@fullcent ~]# date -R
Wed, 13 Mar 2013 15:15:31 +0800
[root@fullcent ~]# cat /etc/sysonfig/clock
cat: /etc/sysonfig/clock: No such file or directory
[root@fullcent ~]# 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/Seoul"
UTC=true
ARC=false
[root@fullcent ~]#
只好手工把它改回到 ZONE="Asia/Shanghai"的状态
改用美洲多伦多时区进行实验:
[root@fullcent ~]# 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.
#? 2
Please select a country.
1) Anguilla                      28) Haiti
2) Antigua & Barbuda              29) Honduras
3) Argentina                      30) Jamaica
4) Aruba                          31) Martinique
5) Bahamas                        32) Mexico
6) Barbados                      33) Montserrat
7) Belize                        34) Nicaragua
8) Bolivia                        35) Panama
9) Bonaire Sint Eustatius & Saba  36) Paraguay
10) Brazil                        37) Peru
11) Canada                        38) Puerto Rico
12) Cayman Islands                39) Sint Maarten
13) Chile                          40) St Barthelemy
14) Colombia                      41) St Kitts & Nevis
15) Costa Rica                    42) St Lucia
16) Cuba                          43) St Martin (French part)

本文发布于:2024-09-21 03:26:54,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/344244.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:时区   文件   时间   看到   修改   没有   工具   图形化
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议