Linux 时间及时区设置
时间以及时区设置
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.
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.查看Bois(cmos)时间(用
#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 时间及时区设置的更多相关文章
- linux 时间和时区设置
在linux中与时间相关的文件有 /etc/localtime /etc/timezone 其中,/etc/localtime是用来描述本机时间,而 /etc/timezone是用来描述本机所属的时区 ...
- Django 时间与时区设置问题
django 时间与时区设置问题 在Django的配置文件settings.py中,有两个配置参数是跟时间与时区有关的,分别是TIME_ZONE和USE_TZ 如果USE_TZ设置为True时,Dja ...
- linux下的时间及时区设置
一.时间设置及同步 1修改系统时间 #date -s 06/18/14 #date -s 14:20:50 2命令查看.设置硬件时间 #hwclock --show 或者clock --show ...
- 【Linux】通过SSH修改调整Linux时间和时区
VPS(Virtual Private Server 虚拟专用服务器)技术,将一部服务器分割成多个虚拟专享服务器的一种服务.大多站长喜欢用美国的VPS,而美国的时间和时区和国内不同,那就需要通过SSH ...
- Django时间与时区设置问题
在Django的配置文件settings.py中,有两个配置参数是跟时间与时区有关的,分别是TIME_ZONE和USE_TZ 如果USE_TZ设置为True时,Django会使用系统默认设置的时区,即 ...
- 查看/修改 Linux 时间和时区
查看/修改Linux时区和时间 一.时区 1. 查看当前时区 date -R 2. 修改设置时区 方法(1) ...
- Linux时间和时区设定
一.时区设定 由于安装系统时采用了UTC,那么什么是UTC呢,简单的说UTC就是0时区的时间,是国际标准,而中国处于UTC+8时区. 使用tzselect命令,过程如下: 可以看到此环境变量已设置,将 ...
- 主机、Docker时间与时区设置总结
最近在使用Docker容器时,部署java程序发现时间输出不对,在修改问题时总结如下. #date [-R] #查看主机时间 #timedatectl #查看主机时区 #tzselect ...
- linux时间方面的设置
例如以下一段代码能够借鉴: static void _sleep_response_timeout(modbus_t *ctx) { #ifdef _WIN32 /* usleep doesn't e ...
随机推荐
- Swift5 语言指南(十九) 错误处理
错误处理是响应程序中的错误条件并从中恢复的过程.Swift为在运行时抛出,捕获,传播和操纵可恢复的错误提供了一流的支持. 某些操作无法保证始终完成执行或生成有用的输出.Optionals用于表示缺少值 ...
- 多核CPU配合负载均衡可以这样用,为老板省点钱
负载均衡作为一个处理高并发,大流量的访问的业务场景,已经几乎是常识性的知识了. 而本文的意义在于需求:由于大流量请求,导致服务无法正常响应,在不增加购买机器成本的场景下,如何提高服务器的业务处理能力? ...
- windows快速打开命令窗口方式[利刃篇]
windows当然是窗口界面操作了,谁有事没事去用什么命令行啊,但是当你要用的时候,也要会用才行哦. 打开命令行的方式小说一下: 1.开始 > 运行 > cmd , enter, ok ...
- tk.mybatis通用工具采坑记
tk.mybatis通用工具pom <!--mybatis依赖--> <dependency> <groupId>org.mybatis.spring.boot&l ...
- Zabbix--1
ZABBIX 与其他监控程序比较.
- Typescript 学习笔记三:函数
中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...
- Python内置类型(1)——真值测试
python中任何对象都能直接进行真假值的测试,用于if或者while语句的条件判断,也可以做为布尔逻辑运算符的操作数 python中任何对象都能直接进行真假值的测试,而不需要额外的类型转换 这一点是 ...
- Android_Studio_Checkout_Github_Error"Cannot run program "git.exe":CreateProcess error = 2
答案都在这了,如果你有下载过git而不是github,那么你可以指定git.exe给android studio 正如这样:
- 从零开始学 Web 之 CSS3(八)CSS3三个案例
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- Spring Boot Actuator监控应用
微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...