[root@ ~]# date "+%Y"
2019
[root@ ~]# date "+%Y%m%d"
20190826
[root@localhost ~]# date -d 2019-07-16 "+%Y-%m-%d %H:%M:%S" 2019-07-16 00:00:00 [root@localhost ~]# date -d '1 month ago' --->一個月之前的時間點 2019年 06月 16日 星期日 16:05:57 CST [root@localhost ~]# date -d '1 month after' ---》無效方法 date: 無效的日期"1 month after" [root@localhost ~]# date -d '1 month' ---》一個月以后的時間點 2019年 08月 16日 星期五 16:06:26 CST [root@localhost ~]# date -d '2 hour' ----》兩個小時之后 2019年 07月 16日 星期二 18:07:06 CST [root@localhost ~]# date -d '2 hour ago' ----》兩個小時之前 2019年 07月 16日 星期二 14:07:20 CST
#三天以前按照一定的格式輸出
[cbi@NC01857682 ~]$ date -d "3 days ago" "+%Y-%m-%d %H:%M:%S"
2019-07-21 17:23:33
date命令將時間戳轉化成格式化時間
# date "+%Y-%m-%d %H:%M:%S" -d @1568880277 2019-09-19 16:04:37
date -s 設置服務器時間
date -s "2019-12-10 00:00:00" hwclock -w
如何同步硬件時鍾? NTP一般只會同步system clock. 但是如果我們也要同步RTC(hwclock)的話那么只需要把下面的選項打開就可以了 代碼: # vi /etc/sysconfig/ntpd SYNC_HWCLOCK=yes