如何设置Centos6.4java 获取系统时区的时区

&centos6.x 和centos7.x在时区方面有点差距,本文是针对centos6.x进行介绍。
其实在我的一个博文里,在安装系统的时候就可以进行时区的设置,本文介绍的是用命令进行时区查看和设置。
&&提君博客原创& http://www.cnblogs.com/tijun/& &&
使用date命令查看时区
[root@ltt1 ~]# date -R
Thu, 28 Sep 2017 00:31:54 +0800
我们国家的东八区(+0800)
查看clock系统配置文件
[root@ltt1 ~]# cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"
我的系统设置的时区为Asia/Shanghai,也就是我们国家的东八区(+0800)。
下面介绍设置时区的一种方式。
使用tzselect设置时区
[root@ltt1 sysconfig]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
2) Americas
3) Antarctica
4) Arctic Ocean
6) Atlantic Ocean
7) Australia
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
Please select a country.
1) Afghanistan
18) Israel
35) Palestine
2) Armenia
36) Philippines
3) Azerbaijan
20) Jordan
4) Bahrain
21) Kazakhstan
38) Russia
5) Bangladesh
22) Korea (North)
39) Saudi Arabia
23) Korea (South)
40) Singapore
24) Kuwait
41) Sri Lanka
8) Cambodia
25) Kyrgyzstan
43) Taiwan
10) Cyprus
27) Lebanon
44) Tajikistan
11) East Timor
45) Thailand
12) Georgia
29) Malaysia
46) Turkmenistan
13) Hong Kong
30) Mongolia
47) United Arab Emirates
31) Myanmar (Burma)
48) Uzbekistan
15) Indonesia
49) Vietnam
34) Pakistan
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
The following information has been given:
Beijing Time
Therefore TZ='Asia/Shanghai' will be used.
Local time is now:
Thu Sep 28 00:10:57 CST 2017.
Universal Time is now:
Wed Sep 27 16:10:57 UTC 2017.
Is the above information OK?
You can make this change permanent for yourself by appending the line
TZ='Asia/Shanghai'; export TZ
to the file '.profile' in 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
根据提示一步一步选择就可以。
&&提君博客原创& http://www.cnblogs.com/tijun/& &&
注意:上面最后的几行的说明,大概意思是说,tzselect命令只是输出一个标准的TZ写法,并不生效,你还需要将这个TZ放到你的home目录下的.profile文件里
如:TZ='Asia/Shanghai'; export TZ,同时还有注销再重新登录系统,才可设置永久生效。
下面亲测进行检验一下
我当前时区和时间
[root@ltt1 ~]# date -R;cat /etc/sysconfig/clock
Thu, 28 Sep 2017 00:46:39 +0800
ZONE="Asia/Shanghai"
tzselect设置一个其他的时区,只给出个结果,一些步骤不再贴出
The following information has been given:
Therefore TZ='America/Anguilla' will be used.
Local time is now:
Wed Sep 27 12:48:20 AST 2017.
Universal Time is now:
Wed Sep 27 16:48:20 UTC 2017.
Is the above information OK?
You can make this change permanent for yourself by appending the line
TZ='America/Anguilla'; export TZ
to the file '.profile' in 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:
America/Anguilla
[root@ltt1 ~]# vi /etc/profile
TZ='America/Anguilla'; export TZ
[root@ltt1 ~]# source /etc/profile
[root@ltt1 ~]# date -R
Wed, 27 Sep 2017 13:01:30 -0400
[root@ltt1 ~]# cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"
额,可以看到 由 +0800& 变成了 -0400
说明成功了,就是文件内容没有更改,目前不知是什么原因。
&&提君博客原创& http://www.cnblogs.com/tijun/& &&
阅读(...) 评论()博客访问: 178056
博文数量: 124
博客积分: 10
博客等级: 民兵
技术积分: 506
注册时间:
分类: LINUX 13:32:22
[root@newmch~]# 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
&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.
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
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
The following information has been given:
& & & & China
& & & & east China - Beijing, Guangdong, Shanghai, etc.
Therefore TZ='Asia/Shanghai' will be used.
Local time is now: & & &Tue Feb 11 13:27:20 CST 2014.
Universal Time is now: &Tue Feb 11 05:27:20 UTC 2014.
Is the above information OK?
You can make this change permanent for yourself by appending the line
& & & & TZ='Asia/Shanghai'; export TZ
to the file '.profile' in 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
[root@newmch~]# vi /root/.bash_profile&
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
& & & & . ~/.bashrc
# User specific environment and startup programs
TZ='Asia/Shanghai'; export TZ&
PATH=$PATH:$HOME/bin
export PATH
注:TZ='Asia/Shanghai'; export TZ &到profile文件很重要 否则不会发生变化 。
阅读(309) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
请登录后评论。如何设置Centos6.4系统的时区_百度知道
如何设置Centos6.4系统的时区
我有更好的答案
usr/share/zoneinfo/Asia/Shanghai /etc&#47两个方法但是其实都是一样的cp &#47
采纳率:77%
tzselect 命令
为您推荐:
其他类似问题
时区的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。linux修改系统时间和linux查看时区、修改时区的方法
互联网 & 04-27 14:38:37 & 作者:佚名 &
这篇文章主要介绍了linux修改系统时间和linux查看时区、修改时区的方法,需要的朋友可以参考下
一、查看和修改Linux的时区
1. 查看当前时区命令 : &date -R&
2. 修改设置Linux服务器时区方法 A命令 : &tzselect&
方法 B 仅限于RedHat Linux 和 CentOS命令 : &timeconfig&
方法 C 适用于Debian命令 : &dpkg-reconfigure tzdata&
3. 复制相应的时区文件,替换系统时区文件;或者创建链接文件cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime
例如:在设置中国时区使用亚洲/上海(+8)
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
二、查看和修改Linux的时间
1. 查看时间和日期命令 : &date&
2.设置时间和日期例如:将系统日期设定成日的命令
命令 : &date -s 11/03/2009&
将系统时间设定成下午5点55分55秒的命令
命令 : &date -s 17:55:55&
3. 将当前时间和日期写入BIOS,避免重启后失效命令 : &hwclock -w&
date不加参数可以直接看到当前日期时间
cal不加参数可以直接看到本月月历
大家感兴趣的内容
12345678910
最近更新的内容在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
一台测试服务器,之前设置为Asia/Shanghai,但是前两天突然时区失效了。
失效之前曾经升级过libc-2.12.so -& libc-2.14.so,不知道有没有关系。
Fri Feb 10 07:01:22 Local time zone must be set--see zic manual page 2017
Fri, 10 Feb :10 +0000
用了tzselect重新选择,无效。
重置/etc/localtime,无效
rm -f /etc/localtime
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
/etc/sysconfig/clock设置也无效
ZONE="Asia/Shanghai"
TZ="Asia/Shanghai"
最后在.bash_profile里面设置TZ='America/Nassau'; export TZ,却只对当前用户有效,对其他用户还是无效的。
# sudo -u www-data date
Fri Feb 10 06:52:02 Local time zone must be set--see zic manual page 2017
系统版本如下:
LSB Version:
:base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:
Description:
CentOS release 6.4 (Final)
google,百度都翻了个底,还是找不到解决办法,只能来这里求助了。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
好吧,自己解决了。
原因就是升级libc.so.6导致的!
GNU中对中指出,如果TZ没有值,会默认选择时区,具体地址由libc.so.6这个库决定。在升级前,centos的默认时区文件为/etc/localtime。而我新编译的库时,设置了--prefix=/usr/local/glibc-2.14,导致默认路径为变成了/usr/local/glibc-2.14/etc/localtime,自然就找不到默认时区了。
解决方案:
ln -sf /etc/localtime /usr/local/glibc-2.14/etc/localtime
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
ln -sf /etc/localtime /usr/local/glibc-2.14/etc/localtime
就是这句。正解
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。}

我要回帖

更多关于 linux 系统时区 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信