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
转载于:https://blog.51cto.com/zchui/2150627