欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Linux命令之日期时间命令date使用实例

程序员文章站 2023-11-11 09:44:46
这篇文章主要介绍了Linux命令之日期时间命令date使用实例,本文着重讲解了它的格式化参数,同时讲解了使用语法和使用实例,需要的朋友可以参考下... 15-06-25...

date用法1:

       格式:date [option]... [+format]

       format controls the output.  interpreted sequences are:


       %%     a literal %

       %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, space padded ( 0..23); same as %_h


       %l     hour, space padded ( 1..12); same as %_i


       %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 time zone (e.g., -0400)


       %:z    +hh:mm numeric time zone (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)


       by default, date pads numeric fields with zeroes.  the following optional flags may follow `%':


       -      (hyphen) do not pad the field


       _      (underscore) pad with spaces


       0      (zero) pad with zeros


       ^      use upper case if possible


       #      use opposite case if possible

例如:

1.年月日

复制代码
代码如下:

$ date +%y%m%d
20150107

2.年月日,年只保留后两位

复制代码
代码如下:

~$ date +%y%m%d
150107

3.小时分钟秒

复制代码
代码如下:

~$ date +%h%m%s
233045

4.年月日时分秒

复制代码
代码如下:

~$ date +%y%m%d%h%m%s
20150107233145