UNIX date命令简介

作者: velcbo 2014-07-14 10:25:10
date 命令
参数含义:
%a :显示星期简写 (Sun..Sat)
%A :显示完整星期(Sunday..Saturday)
%b :显示月份简写(Jan..Dec)
%B :显示完整月份(January..December)
%c :显示当前日期,格式如:Thu Aug 13 11:04:05 2009
%C :显示世纪,当前年除100后的整数部分,如当前为20 (year divided by 100 and truncated to an integer)[00-99]
%d :显示当前那日 ,范围(01..31)
%D :日期,格式如(mm/dd/yy)
%e :显示当前日,与%d不同的是%d显示01,而%e显示1,范围 ( 1..31)
%F :如 %Y-%m-%d的日期格式
%g :the 2-digit year corresponding to the %V week number
%G :the 4-digit year corresponding to the %V week number
%h :与 %b相同
%H :24小时制的小时,范围(00..23)
%I :12小时制的小时,范围(01..12)
%j :一年中的那天,范围是(001..366)
%k :24小时制的小时,只显示1而不显示01,范围( 0..23)
%l :12小时制的小时,只显示1而不显示01,范围( 1..12)
%m :显示月份,范围(01..12)
%M :显示分钟,范围(00..59)
%n :新行
%N :显示秒(000000000..999999999)
%p :locale's upper case AM or PM indicator (blank in many locales)
%P :locale's lower case am or pm indicator (blank in many locales)
%r :时间, 12小时制,格式(hh:mm:ss [AP]M)
%R :时间, 24小时制,格式(hh:mm)
%s :从1970-01-01 00:00:00到现在的秒数。seconds since '00:00:00 1970-01-01 UTC' (a GNU extension)
%S :秒,显示当前时间的秒,范围(00..59);  Displays the seconds as a decimal number (00- 59).
%t :a horizontal tab
%T :时间, 24-hour (hh:mm:ss)24小时制
%u :day of week (1..7); 1 represents Monday,星期几,其中1代表星期一,其他类似。
%U :week number of year with Sunday as first day of week (00..53),一年中的第几个星期,其中以星期日为第一天
%V :week number of year with Monday as first day of week (01..53),一年中的第几个星期,其中以星期一为第一天
%w :day of week (0..6); 0 represents Sunday,星期几,其中0代表星期日,1代表星期一,其他类似
%W :week number of year with Monday as first day of week (00..53),一年中的第几个星期,其中星期一为第一天,范围从00-53
%x :locale's date representation (mm/dd/yy) 按mm/dd/yy格式显示日期
%X :locale's time representation (%H:%M:%S)等于%H:%M:%S
%y :last two digits of year (00..99)显示2位数的年
%Y :year (1970...) 显示4位数的年
%z :RFC-2822 style numeric timezone (-0500) (a nonstandard extension)
%Z :time zone (e.g., EDT), or nothing if no time zone is determinable

例子:
date +%Y-%m-%d-%k:%M:%S
2012-12-24-21:21:33

echo "`date \"+%Y-%m-%d %H:%M:%S\"`"
2012-12-24 21:21:46

来源:Linux社区

相关资讯