date命令說明

2022-06-26 02:09:16 字數 3012 閱讀 7214

基本使用格式:

date [-d "time-to-display"] +"format-to-display"
-d指定要顯示的時間,如果不指定預設為當前時間;後邊的+後的字串為指定的輸出格式,類式c的print的格式。常用示例如下:

date -d "

1 day ago

" +"

%y-%m-%d

"date -d "

30 day ago

" +"

%y-%m-%d

"date -d "

+ 1 day

" +"

%y-%m-%d

"date -d "

- 1 month

" +"

%y-%m-%d

"date -d "

20170427

" +"

%y-%m-%d

"date -d "

20170427

" +"

輸出為:%y-%m-%d

支援的輸出項:

%a     locale』s abbreviated weekday name (e.g., sun)

%a locale』s full weekday name (e.g., sunday)

%b locale』s abbreviated month name (e.g., jan)

%b locale』s full month name (e.g., january)

%c locale』s date and time (e.g., thu mar 3

23:05:25

2005

) %c century; like %y, except omit last two digits (e.g., 20

) %d day of month (e.g, 01

) %d date; same as %m/%d/%y

%e day of month, space padded; same as %_d

%f full date; same as %y-%m-%d

%g last two digits of year of iso week number (see %g)

%g year of iso week number (see %v); normally useful only with %v

%h same as %b

%h hour (00..23

) %i hour (01..12

) %j day of year (001..366

) %k hour ( 0..23

) %l hour ( 1..12

) %m month (01..12

) %m minute (00..59

) %n a newline

%n nanoseconds (000000000..999999999

) %p locale』s equivalent of either am or pm; blank if

not known

%p like %p, but lower case

%r locale』s 12-hour clock time (e.g., 11:11:04

pm) %r 24-hour hour and minute; same as %h:%m

%s seconds since 1970-01-01

00:00:00

utc %s second (00..60

) %t a tab

%t time; same as %h:%m:%s

%u day of week (1..7); 1

is monday

%u week number of year, with sunday as first day of week (00..53

) %v iso week number, with monday as first day of week (01..53

) %w day of week (0..6); 0

is sunday

%w week number of year, with monday as first day of week (00..53

) %x locale』s date representation (e.g., 12/31/99

) %x locale』s time representation (e.g., 23:13:48

) %y last two digits of year (00..99

) %y year

%z +hhmm numeric timezone (e.g., -0400

) %:z +hh:mm numeric timezone (e.g., -04:00

) %::z +hh:mm:ss numeric time zone (e.g., -04:00:00

) %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30

) %z alphabetic time zone abbreviation (e.g., edt)

date的詳細說明

用法 date 選項 格式 或 date u utc universal mmddhhmm cc yy ss 以給定的格式顯示當前時間,或是設定系統日期。d,date 字串 顯示指定字串所描述的時間,而非當前時間 f,file 日期檔案 類似 date,從日期檔案中按行讀入時間描述 r,refere...

date命令參考

1 man手冊 1.1 呼叫格式 date 選項 格式 date u utc universal mmddhhmm cc yy ss 1.2 功能 按格式顯示時間或設定系統時間。1.3 選項 d,date string 顯示string指示的時間,string是比較隨性的可讀的字串,比如說 2012...

date命令詳解

1 命令 date 2 命令功能 date 可以用來顯示或設定系統的日期與時間。3 命令引數 d 字串 顯示字串所指的日期與時間。字串前後必須加上雙引號 s 字串 根據字串來設定日期與時間。字串前後必須加上雙引號 u 顯示gmt version 顯示版本資訊。4 日期格式字串列表 h 小時 以00 ...