linux 设置时间为昨天,Linux —— 时间(tzselect、timedatactl命令,查看和修改时区,修改时区为东八区)...
一、設(shè)置linux修改時(shí)區(qū)
首先查看當(dāng)前時(shí)區(qū)
#date -R
顯示結(jié)果為:
[root@localhost 20190528]# date -R
Wed, 29 May 2019 19:56:23 +0100
很顯然不是東八區(qū)的時(shí)間。
方案一:使用tzselect命令實(shí)現(xiàn)
1、若不是,準(zhǔn)備修改時(shí)區(qū)
#tzselect
2、查看是不是更改為東八區(qū)
[root@localhost 20190528]# date -R
Wed, 29 May 2019 19:57:14 +0100
結(jié)果非預(yù)期所期望的那樣……怎么回事???
3、經(jīng)排查,第一步中選了yes之后,有下面一段話。
此時(shí)時(shí)間并沒有修改,需要執(zhí)行TZ='Asia/Shanghai'; export TZ,并將這條命令寫入.bash_profile文件。
4、執(zhí)行命令TZ='Asia/Shanghai'; export TZ;
#TZ='Asia/Shanghai'; export TZ
5、再次查看是不是更改為東八區(qū),顯示成功
[root@localhost 20190528]# date -R
Wed, 29 May 2019 22:59:13 +0400
方案二:使用timedatectl命令
比較新的linux發(fā)行版(筆者嘗試過ubuntu 16.04和centos7)均支持一個(gè)方便的命令timedatectl
1、使用timedatectl命令,查看當(dāng)前的時(shí)區(qū)
[root@localhost ~]# timedatectl status
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.
Local time: 三 2019-05-29 19:17:22 UTC
Universal time: 三 2019-05-29 19:17:22 UTC
RTC time: 三 2019-05-29 19:17:22
Time zone: n/a (UTC, +0000)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
2、使用timedatectl命令,設(shè)置時(shí)區(qū)為東八區(qū)
# timedatectl list-timezones | grep "Asia/S"
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk
# timedatectl set-timezone "Asia/Shanghai"
3、查看當(dāng)前的時(shí)區(qū)狀態(tài)
# timedatectl status
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.
Local time: 三 2019-05-29 23:23:59 SCT
Universal time: 三 2019-05-29 19:23:59 UTC
RTC time: 三 2019-05-29 19:23:59
Time zone: Asia/Shanghai (SCT, +0400)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
4、使用date命令查看,其顯示并不是東八區(qū)……
我試了好久,,,,都沒有成功!!不知道少什么配置文件,哪位大神曉得,歡迎留言指教!
# date -R
Wed, 29 May 2019 16:32:58 -0300
二、設(shè)置系統(tǒng)時(shí)間為此刻的北京時(shí)間
假設(shè)時(shí)區(qū)現(xiàn)在是正確的,此時(shí)的正確時(shí)間應(yīng)該是“2019-5-29 23:50:00”;
//查看此時(shí)的時(shí)區(qū)與系統(tǒng)時(shí)間
# date -R
# timedatectl status
方案一、使用date命令:
………………date的使用………………Linux —— 時(shí)間(date設(shè)置系統(tǒng)時(shí)間)
[root@localhost ~]# date -s "2019-05-19 23:51:46" //設(shè)置時(shí)間為此刻北京時(shí)間
2019年 05月 19日 星期日 23:51:46 SCT
[root@localhost ~]# date //查看時(shí)間
2019年 05月 19日 星期日 23:51:47 SCT
方案二、查看此時(shí)的硬件時(shí)間,若硬件時(shí)間正確可以同步系統(tǒng)時(shí)間與硬件時(shí)間相同
……………………h(huán)wclock的使用…………Linux —— 時(shí)間(hwlock設(shè)置硬件時(shí)間)
[root@localhost ~]# hwclock -r //查看此時(shí)的硬件時(shí)間
2019年05月29日 星期三 23時(shí)52分55秒 -0.788625 秒
[root@localhost ~]# hwclock --hctosys //使得系統(tǒng)時(shí)間變換為硬件時(shí)間
[root@localhost ~]# date //再次查看當(dāng)前時(shí)間
2019年 05月 29日 星期三 23:53:12 SCT
參考鏈接:
https://www.cnblogs.com/flying607/p/9900071.html
https://jingyan.baidu.com/article/39810a235cd638b637fda664.html
https://www.cnblogs.com/jiu0821/p/5999566.html
總結(jié)
以上是生活随笔為你收集整理的linux 设置时间为昨天,Linux —— 时间(tzselect、timedatactl命令,查看和修改时区,修改时区为东八区)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux写程序四则运算,Shell编程
- 下一篇: 嵌入式linux 配置usb otg,嵌