date

最後更新: 2019-09-19

目錄

  • Usage
  • Display
  • 應用
  • Cheat List
  • hpet

 


Usage

 

date [OPTION]... [+FORMAT]

 

FORMAT

  • %S       # second
  • %M       # minute
  • %H       # hour

day

  • %d       # "09"
  • %e       # " 9"   <- space padded

month

  • %m      # month (e.g. "09")
  • %b       # locale’s abbreviated month name (e.g. "Jan")
  • %B       # locale’s full month name (e.g. "January")

year

  • %Y       # year (e.g. "2016")
  • %y       # year (e.g. "16")

full

  • %F     full date; same as %Y-%m-%d
  • %T     time; same as %H:%M:%S; 09:06:12

 

  • %s        # seconds since 1970-01-01 00:00:00 UTC

 

  • %a         # Mon, Tue, Wed, Thu, Fri, Sat, Sun

 


Display

 

-d, --date=STRING                        # display time described by STRING. Default "now"

# 找出某日是星期幾

date -d 2016-10-17 +%a

Mon

# Convert seconds since the epoch

date --date='@1417599218'

Wed Dec  3 17:33:38 HKT 2014

# Date In the Future

date --date='tomorrow'                 
date --date='10 day'
date --date='10 week'
date --date='10 month'
date --date='10 year'

# Date In the Past

date --date='yesterday'
date --date='10 day ago'
date --date='10 week ago'
date --date='10 month ago'
date --date='10 year ago'

 


應用

 

[1] 設定時間 ("-s")

-s, --set=STRING

i.e.

date -s "23:14:00"

 

[2] 找出某天的 backup log ("+%X")

grep $(date '+%d/%b/%Y') /var/log/rsnapshot

[19/Sep/2019:03:00:01] /usr/bin/rsnapshot sync: started
...
[19/Sep/2019:03:00:53] /usr/bin/rsnapshot daily: started
...
[19/Sep/2019:03:01:02] /usr/bin/rsnapshot daily: completed successfully

 


Cheat List

 

display format: date +%Y%m%d

set time: date -s "23:14:00"

 

Creative Commons license icon Creative Commons license icon