date :print or set the system date and time
打印或設置系統日期和時間
使用格式
date [OPTION]… [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm][[CC]YY[.ss]]
描述(description):
Display the current(當前的,現在的) time in the given FORMAT(格式), or set the system date.
以給定的格式顯示當前時間,或者設置日期。
常用選項(option)
-d
,--date=STRING
display time described(描述) by STRING, not "now"按照指定的字符串的描述打印時間,而不是當前時間
比如“昨天” “幾天前”“幾天後”
>[root@centos6 ~]#date -d yesterday
>Tue Jul 24 20:20:41 CST 2018
-f
,--file=DATEFILE
like --date once for each line of DATEFILE按行打印出文件中描述的時間
> [root@centos6 ~]#date -f time.txt
>Tue Jul 24 20:42:17 CST 2018
>Fri Jul 27 20:42:17 CST 2018
-r
,--reference=FILE
display the last modification(修改) time of FILE打印文件的最近修改時間
> [root@centos6 ~]#date -r fa.tex
>Mon Jul 23 16:26:55 CST 2018
-s
,--set=STRING
set time described by STRING按照字符串描述 設置時間
-u
,--utc
,--universal
print or set Coordinated Universal Time打印或設置格林威治英國時間
--help
display this help and exit打印幫助信息和退出
--version
output version information and exit輸出版本信息和退出
FORMAT controls the output . Interpreted(解釋) sequences(序列) are:
控制輸出格式。解釋序列如下
%a
Local's abbreviated weekday name(e.g Sun)
本地星期名稱的縮寫
>[root@centos6 ~]#date +%a
>Thu
%A
Local's full weekday name(e.g Sunday)
本地星期全稱
>[root@centos6 ~]#date +%A
>Thursday
>星期四
%b
Local's abbreviated month name.(e.g Jan)
本地月份名縮寫
>[root@centos6 ~]#date +%b
>Jul
%h
Same as %b
顯示當前月份的縮寫
>[root@centos6 ~]#date +%h
>Jul
%B
Local's full month name.(e.g January)
本地月份名全稱
>[root@centos6 ~]#date +%B
>July
>七月
%c
Local's date and time (e.g ,Thu Mar 3 23:05:25 2005)
>[root@centos6 ~]#date +%c
>Thu 26 Jul 2018 09:26:18 AM CST
>2018年7月26日星期四(上午)09:26:18
%C
century:like %Y,except(除了) omit(省略) last two digits(數字)
世紀:和%Y一樣,除了省略最後兩個數字
>[root@centos6 ~]#date +%C
>20
%Y
Year 年>[root@centos6 ~]#date +%Y
>2018
%y
Last two digits of year(00..99)
年份的最後兩位數字(從00到99)
>[root@centos6 ~]#date +%y
>18
%m
month(01..12)
月份(從01-12)
>[root@centos6 ~]#date +%m
> 07
%d
Day of month(01..31)
日(從01-31)
>[root@centos6 ~]#date +%d
>26
%e
Day of month,space padded(填充),same as %_d(1..31)
日期,空格被填充,等同於%_d(從1-31)
>[root@centos6 ~]#date -d -20day +%e
>6
>[root@centos6 ~]#date -d -20day +%_d
>6
顯示結果爲“6”而不是“06”
%F
Full date,same as %Y-%m-%d
日期全稱,類似於%Y-%m-%d格式顯示結果
>[root@centos6 ~]#date +%F
>2018-07-26
>[root@centos6 ~]#date +%Y-%m-%d
>2018-07-26
%D
Date, same as %m%d%Y
日期,類似於%m%d%Y
>[root@centos6 ~]#date +%D
>07/26/18
%g
last two digits of year of ISO week number (see %G)
週數年份後兩個數字
>[root@centos6 ~]#date +%g%V
>1830
>18年第30周
%G
year of ISO week number (see %V); normally useful only with %V
顯示當前爲一年中的第幾周 ,通常只和%V一起使用
>[root@centos6 ~]#date +%G%V
> 201830
2018年第30周
%U
Week number of year,with Sunday as first day of week (00..53)
一年中第幾周,以週日作爲一週的第一天
> [root@centos6 ~]#date +%V
>30
%W
week number of year, with Monday as first day of week (00..53)
一年中的第幾周,以週一爲每週的第一天
>[root@centos6 ~]#date +%W
>30
%V
ISO week number, with Monday as first day of week(01-53)
國際標準週數,以週一作爲一週的第一天,顯示當前爲一年中的第幾周
>[root@centos6 ~]#date +%V
>30
%H
Hour (00..23)
小時,24小時制,從00到23
>[root@centos6 ~]#date +%H
>14
%k
Hour, space padded(0..23); same as %_H
小時,24小時制,從0到23,類似於%_H
>[root@centos6 ~]#date -d -10hours +%_H
>4
>[root@centos6 ~]#date -d -10hours +%k
>4
>時間顯示爲“4”而不是“04”
%I
Hour,(01-12)
小時,12小時制,從01到12
>[root@centos6 ~]#date +%I
>02
%l
Hour, space padded (1-12); same as %_I
小時,12小時制,從1到12,類似於%_I
>[root@centos6 ~]#date +%l
>2
>[root@centos6 ~]#date +%_I
>2
>時間顯示爲“2”,而不是“02”
%M
Minute, (00..59)
分鐘,從00到59
%S
Second,(00.59)
秒鐘,從00到59
%T
Same as %H:%M:%S
>[root@centos6 ~]#date +%T
> 15:16:42
%j
Day of year (001..366)
顯示一年當中的第幾天(從001到366)
>[root@centos6 ~]#date +%j
>207
%n
A new line
換行顯示
>[root@centos6 ~]#date +%j%n%F
>207
>2018-07-26
%N
nanoseconds (000000000..999999999)
納秒,表示一秒之內的多少納秒。1納秒等於十億分之一秒
%p
locale's equivalent(相當於) of either AM or PM; blank if not known
顯示當前時間是AM(上午)還是PM(下午),如果不知道則空白
>[root@centos6 ~]#date -d -10hours +%p
>AM
%P
Like %p, but lower case
相當於%p ,不過是用小寫字母表示
%r
locale's 12-hour clock time (e.g., 11:11:04 PM)
顯示12小時制時間
>[root@centos6 ~]#date +%r
>03:01:43 PM
%R
24-hour hour and minute; same as %H:%M
24小時制顯示時間,相當於%H:%M
>[root@centos6 ~]#date +%R
>15:11
%s
seconds since 1970-01-01 00:00:00 UTC
自從1970年1月1日起,UTC時間經過的秒數
>[root@centos6 ~]#date +%s
>1532589239
%t
A tab
插入一個“Tab”
>[root@centos6 ~]#date +%Y%t%m%t%d
>2018 07 26
%u
Day of week (1..7):1 is Monday
一週第幾天,1表示星期一
>[root@centos6 ~]#date +%u
>4
%w
Day of week (0..6);0 is Sunday
一週第幾天,0表示星期日
>[root@centos6 ~]#date +%w
>4
%x
locale's date representation (e.g., 12/31/99)
日期表示格式
>[root@centos6 ~]#date +%x
>07/26/2018
%X
locale's time representation (e.g., 23:13:48)
時間表示
>[root@centos6 ~]#date +%X
>03:36:05 PM
%z
+hhmm numeric time zone
顯示當前時區
>[root@centos6 ~]#date +%z
>+0800
+%:z
,+%::z
,+%:::z
+hh:mm:ss numeric time zone (e.g., -04:00:00)
>[root@centos6 ~]#date +%:z
>+08:00
>[root@centos6 ~]#date +%::z
>+08:00:00
>[root@centos6 ~]#date +%:::z
>+08
%Z
alphabetic(字母的) time zone abbreviation(縮寫) (e.g., EDT)
時區字母縮寫
>[root@centos6 ~]#date +%Z
>CST