Linux日期時(shí)間查看和設(shè)置相關(guān)命令

原文地址: http://www.itdecent.cn/p/7a770f541f91

1. 相關(guān)命令

1. date: print or set the system date and time
2. hwclock: query or set the hardware clock (RTC)
3. timedatectl: Control the system time and date

2. 查看

2.1 date命令

# date
Thu Jul 13 16:49:54 CST 2017

2.2 hwclock命令

# hwclock -r
Thu 13 Jul 2017 04:50:49 PM CST  -0.861128 seconds

需要權(quán)限

2.3 timedatectl命令

$ timedatectl
      Local time: Thu 2017-07-13 17:29:18 CST
  Universal time: Thu 2017-07-13 09:29:18 UTC
        RTC time: Thu 2017-07-13 09:29:09
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

3. 時(shí)間設(shè)置

3.1 date命令

語(yǔ)法

date --set='STRING'
date -s 'STRING'

示例:

# date -s '2017-07-13 15:11:00'
# date --set='2017-07-13 15:11:00'

如果參數(shù)只填寫日期則時(shí)間默認(rèn)為0:

# date -s '20170811'
Fri Aug 11 00:00:00 UTC 2017

可以單獨(dú)設(shè)置時(shí)間:

# date -s '14:12:32'
Fri Aug 11 14:12:32 UTC 2017

3.2 hwclock命令

將系統(tǒng)時(shí)間寫入到hardware,這樣以后重啟后設(shè)置的時(shí)間仍會(huì)生效:

# hwclock -w

3.3 timedatectl命令

# timedatectl set-time 'String'

示例:

# timedatectl set-time '2015-11-23 08:10:40'
# timedatectl set-time '10:42:43'

如果設(shè)置了自動(dòng)同步時(shí)間的功能,設(shè)置將會(huì)無(wú)效:

Failed to set time: Automatic time synchronization is enabled

4. 時(shí)區(qū)設(shè)置

timedatectl status // 列出系統(tǒng)時(shí)區(qū)和時(shí)間信息
timedatectl list-timezones // 列出所有時(shí)區(qū)
timedatectl set-timezone 'Asia/Shanghai’

Reference

  1. Linux Set Date and Time From a Command Prompt
  2. date
  3. Using the hwclock Command
  4. Linux下使用timedatectl命令時(shí)間時(shí)區(qū)操作詳解
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容