ubuntu下更改时区_Ubuntu修改时区的两种方法

第一种修改方式tzselect

服务器date时间不准:

jingke@ubuntu:~# date

Tue, 05 Nov 2019 21:08:31 -0500

第二步:

第三步:

第四步

第五步

修改/etc/localtime文件

控制系统时区的文件是/etc/localtime。只要把这个文件复制成相应时区的文件,系统时区就改成相应的时间了。

时区信息在:/usr/share/zoneinfo里。比如需要把本机 时区改成Shanghai的时间:

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

这两条指令都可以更改。

使用date查看时间

第二种修改方式 timedatectl

1.查看当前时间状态

查看当前时间状态 timedatectl status :

wxs@ubuntu:~/6-1/task4$ timedatectl status

Local time: Tue 2017-11-07 18:14:30 PST

Universal time: Wed 2017-11-08 02:14:30 UTC

RTC time: Wed 2017-11-08 02:14:29

Time zone: America/Los_Angeles (PST, -0800)

Network time on: yes

NTP synchronized: yes

RTC in local TZ: no

系统显示的时间是错误的,错误原因也是显而易见的,使用的是America/Los_Angeles的时区。

因此只要修改时区就能保证时间的正确。

2.修改时区

所有的时区名称存储在/usr/share/zoneinfo文件中。

执行命令timedatectl set-timezone "Asia/Shanghai" 就可以将时区设为上海时区。

==== AUTHENTICATING FOR org.freedesktop.timedate1.set-timezone ===

Authentication is required to set the system timezone.

Authenticating as: wxs,,, (wxs)

Password:

==== AUTHENTICATION COMPLETE ===12345

重新查看当前时间状态 timedatectl status :

wxs@ubuntu:~/6-1/task4$ timedatectl status

Local time: Wed 2017-11-08 10:15:45 CST

Universal time: Wed 2017-11-08 02:15:45 UTC

RTC time: Wed 2017-11-08 02:15:45

Time zone: Asia/Shanghai (CST, +0800)

Network time on: yes

NTP synchronized: yes

RTC in local TZ: no12345678

此时时间已经正常了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值