几种 Unix 程序的日期格式表达方法

http://www.sina.com.cn 2006年11月18日 21:58  ChinaByte

  一、find 命令

  %Ck 按照文件状态修改时间,用指定的格式符 k 表示。

  %Tk 按照文件最近修改时间,用指定的格式符 k 表示。

  %Ak 按照最近存取时间,用指定的格式符 k 表示。

  格式符 k 的含义:

  时间字段:

  H hour (00..23)

  I hour (01..12)

  k hour ( 0..23)

  l hour ( 1..12)

  M minute (00..59)

  p locale's AM or PM

  r time, 12-hour (hh:mm:ss [AP]M)

  S second (00..61)

  T time, 24-hour (hh:mm:ss)

  X locale's time representation (H:M:S)

  Z time zone (e.g., EDT), or nothing if no time zone is determinable

  日期字段:

  a locale's abbreviated weekday name (Sun..Sat)

  A locale's full weekday name, variable length (Sun-

  day..Saturday)

  b locale's abbreviated month name (Jan..Dec)

  B locale's full month name, variable length (Jan-

  uary..December)

  c locale's date and time (Sat Nov 04 12:02:33 EST

  1989)

  d day of month (01..31)

  D date (mm/dd/yy)

  h same as b

  j day of year (001..366)

  m month (01..12)

  U week number of year with Sunday as first day of

  week (00..53)

  w day of week (0..6)

  W week number of year with Monday as first day of

  week (00..53)

  x locale's date representation (mm/dd/yy)

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

  Y year (1970...)

  二、date 命令

  %a locale's abbreviated weekday name (Sun..Sat)

  %A locale's full weekday name, variable length (Sunday..Saturday)

  %b locale's abbreviated month name (Jan..Dec)

  %B locale's full month name, variable length (January..December)

  %c locale's date and time (Sat Nov 04 12:02:33 EST 1989)

  %C century (year divided by 100 and truncated to an integer)

  [00-99]

  %d day of month (01..31)

  %D date (mm/dd/yy)

  %e day of month, blank padded ( 1..31)

  %F same as %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 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 upper case AM or PM indicator (blank in many locales)

  %P locale's lower case am or pm indicator (blank in many locales)

  %r time, 12-hour (hh:mm:ss [AP]M)

  %R time, 24-hour (hh:mm)

  %s seconds since '00:00:00 1970-01-01 UTC' (a GNU extension)

  %S second (00..60); the 60 is necessary to accommodate a leap sec-

  ond

  %t a horizontal tab

  %T time, 24-hour (hh:mm:ss)

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

  %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

  %W week number of year with Monday as first day of week (00..53)

  %x locale's date representation (mm/dd/yy)

  %X locale's time representation (%H:%M:%S)

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

  %Y year (1970...)

  %z RFC-2822 style numeric timezone (-0500) (a nonstandard extension)

  %Z time zone (e.g., EDT), or nothing if no time zone is determinable

  三、ls 命令

  ls 按照日期排序的格式,日期可以用 date 命令的格式指定。

  四、php

  字符 说明 返回值例子

  a 小写的上午和下午值 am 或 pm

  A 大写的上午和下午值 AM 或 PM

  B Swatch Internet 标准时 000 到 999

  d 月份中的第几天,有前导零的 2 位数字 01 到 31

  D 星期中的第几天,文本表示,3 个字母 Mon 到 Sun

  F 月份,完整的文本格式,例如 January 或者 March January 到 December

  g 小时,12 小时格式,没有前导零 1 到 12

  G 小时,24 小时格式,没有前导零 0 到 23

  h 小时,12 小时格式,有前导零 01 到 12

  H 小时,24 小时格式,有前导零 00 到 23

  i 有前导零的分钟数 00 到 59

  I 是否为夏令时 如果是夏令时为 1,否则为 0

  j 月份中的第几天,没有前导零 1 到 31

  l(“L”的小写字母) 星期几,完整的文本格式 Sunday 到 Saturday

  L 是否为闰年 如果是闰年为 1,否则为 0

  m 数字表示的月份,有前导零 01 到 12

  M 三个字母缩写表示的月份 Jan 到 Dec

  n 数字表示的月份,没有前导零 1 到 12

  O 与格林威治时间相差的小时数 例如:+0200

  r RFC 822 格式的日期 例如:Thu, 21 Dec 2000 16:01:07 +0200

  s 秒数,有前导零 00 到 59>

  S 每月天数后面的英文后缀,2 个字符 st,nd,rd 或者 th。可以和 j 一起用。

  t 给定月份所应有的天数 28 到 31

  T 本机所在的时区 例如:EST,MDT(【译者注】在 Windows 下为完整文本格式,例如“Eastern Standard Time”,中文版会显示“中国标准时间”)。

  U 从 Unix 纪元(January 1 1970 00:00:00 GMT)开始至今的秒数 参见 time()

  w 星期中的第几天,数字表示 0(表示星期天)到 6(表示星期六)

  W ISO-8601 格式年份中的第几周,每周从星期一开始(PHP 4.1.0 新加的) 例如:42(当年的第 42 周)

  Y 4 位数字完整表示的年份 例如:1999 或 2003

  y 2 位数字表示的年份 例如:99 或 03

  z 年份中的第几天 0 到 366

  Z 时差偏移量的秒数。UTC 西边的时区偏移量总是负的,UTC 东边的时区偏移量总是正的。 -43200 到 43200

  格式字串中不能被识别的字符将原样显示。Z 格式在使用 gmdate() 时总是返回 0。

  五、举例:

  2005年2月9日,

  带前导0的表达: 2005-02-09 05:08:02

  find . -printf "%TY-%Tm-%Td %TH:%TM:%TS \n"

  date +"%Y-%m-%d %H:%M:%S"

  echo date ("Y-m-d H:i:s");

  ?>

  不带前导0的表达:

  2005-2-9 05:08:02

  date +"%Y-%-m-%-d %-H:%-M:%-S"

  2005-2-9 9:08:02

  echo date ("Y-n-j G:i:s");

  ?>

Powered By Google
不支持Flash
·城市对话改革30年 ·新浪城市同心联动 ·诚招合作伙伴 ·企业邮箱畅通无阻
不支持Flash