date時間命令

2021-10-08 19:41:31 字數 2929 閱讀 7338

#顯示系統時間 

[root@qls ~]

# date

wed jul 29 11:19:19 cst 2020

[root@qls ~]

# date +%y #世紀

2020

[root@qls ~]

# date +%y #年代

20[root@qls ~]

# date +%m #月份

07[root@qls ~]

# date +%d #日期

29[root@qls ~]

# date +%y-%m-%d

2020-07-29

[root@qls ~]

# date +%f #顯示日期

2020-07-29

[root@qls ~]

# date +%y-%m-%d

20-07-29

[root@qls ~]

# date +%h #時

11[root@qls ~]

# date +%m #分

23[root@qls ~]

# date +%s #秒

24[root@qls ~]

# date

wed jul 29 11:23:28 cst 2020

[root@qls ~]

# date +%h:%m:%s

11:23:43

[root@qls ~]

# date +%t #顯示時間

11:24:08

[root@qls ~]

# date +%f-%t

2020-07-29-11:24:34

[root@qls ~]

# date +%w #週幾

3[root@qls ~]

# date +%w #今年第幾周

30[root@qls ~]

# date +%s #距離2023年1月1日0分0秒過來多少秒

1595993167

選項: -d #自定義日期

-s #修改日期 時間

[root@qls ~]

# date +%f

2020-07-29

[root@qls ~]

# date -d "-1 day" +%f

2020-07-28

[root@qls ~]

# date -d "+1 day" +%f

2020-07-30

[root@qls ~]

# date -d "+1 month" +%f

2020-08-29

[root@qls ~]

# date -d "-1 month" +%f

2020-06-29

[root@qls ~]

# date -d "-1 year" +%f

2019-07-29

[root@qls ~]

# date -d "+1 year" +%f

2021-07-29

[root@qls ~]

# date

wed jul 29 11:31:42 cst 2020

[root@qls ~]

# date -s 20200730

thu jul 30 00:00:00 cst 2020

[root@qls ~]

# date

thu jul 30 00:00:08 cst 2020

[root@qls ~]

# date -s 2020/07/29

wed jul 29 00:00:00 cst 2020

[root@qls ~]

# date

wed jul 29 00:00:02 cst 2020

[root@qls ~]

# date -s 11:32:30

wed jul 29 11:32:30 cst 2020

[root@qls ~]

# date

wed jul 29 11:32:31 cst 2020

[root@qls ~]

# date -s "20200730 11:00:00"

thu jul 30 11:00:00 cst 2020

#時間同步

ntpdate

[root@qls ~]

# yum install ntpdate -y

向時間伺服器進行同步時間

ntp.aliyun.com

ntp1.aliyun.com ..

.. ntp7.aliyun.com

[root@qls ~]

# ntpdate ntp.aliyun.com

29 jul 11:36:33 ntpdate[31370]: step time server 203.107.6.88 offset -84415.000442 sec

[root@qls ~]

# date

wed jul 29 11:36:35 cst 2020

[root@qls ~]

# date -s 20200730

thu jul 30 00:00:00 cst 2020

[root@qls ~]

# ntpdate ntp.aliyun.com

29 jul 11:36:56 ntpdate[31392]: step time server 203.107.6.88 offset -44591.413933 sec

[root@qls ~]

# date

wed jul 29 11:37:02 cst 2020

linux時間設定命令date

linux下我們一般使用 date s 命令來修改系統時間。如將系統時間設定成1999年12月9日的命令如下。date s 12 09 99 將系統時間設定成下午2點18分9秒的命令如下。date s 14 18 09 注意,這裡說的是系統時間,是linux由作業系統維護的。在系統啟動時,linux...

date 系統時間的命令

這是乙個可以用各種姿勢獲得各種時間的命令。最近在寫自動化定時指令碼時學了一下。參考 比如 利用crontab,每天輸入日誌到乙個log中。直接輸入 date fri jul 5 16 38 56 cst 2019 星期 月 日 時 分 秒 時區 年 關鍵1 使用date 可以很方便的獲取各種時間 重...

日期和時間 date 命令

date命令的格式 date option format 2 在linux shell程式設計中,經常用到日期的加減運算,以前都是自己通過expr函式計算,很麻煩。其實date命令本身提供了日期的加減運算,非常方便。例如 得到昨天的時間 date y m d date 1 day date y m ...