Definition and Usage
定义和用法
The strftime() function parses a time/date generated with strftime().
strftime()函数的作用是:解析由strftime()函数生成的日期/时间。
This function returns an array with the date parsed. The meaning of the returning array keys are:
这个函数以数组的形式返回了解析过的日期。返回的数组关键词如下:
- [tm_sec] - seconds (0-61)
[tm_sec] – 秒(0-61) - [tm_min] - minutes (0-59)
[tm_min] – 分钟(0-59) - [tm_hour] - hour (0-23)
[tm_hour] – 小时(0-23) - [tm_mday] - day of the month (1-31)
[tm_mday] – 月份中包含的天数(1-31) - [tm_mon] - months since January (0-11)
[tm_mon] – 从1月开始的月份(0-11) - [tm_year] - years since 1900
[tm_year] – 从1900年开始经过的年份 - [tm_wday] - days since Sunday (0-6)
[tm_wday] – 从星期日开始计算经过的天数(0-6) - [tm_yday] - days since January 1 (0-365)
[tm_yday] – 从1月1日开始经过的天数(0-365) - [unparsed] - the date part which was not recognized using the specified format, if any
Syntax
语法
Parameter参数 | Description描述 |
date | Required. The string to parse (e.g. returned from strftime()) 必要参数。指定要解析的字符串(例如:从strftime()函数中返回的值) |
format | Required. Specifies the format used in the date: 必要参数。指定了返回结果的方法: - %a - abbreviated weekday name
%a – 缩略的表示星期几的名称 - %A - full weekday name
%A – 表示星期几的全称 - %b - abbreviated month name
%b – 月份简称 - %B - full month name
%B – 月份全称 - %c - preferred date and time representation
%c – 首选的日期和时间表示法 - %C - century number (the year divided by 100, range 00 to 99)
%C – 表示世纪的数字(年份除以100,范围从00到99) - %d - day of the month (01 to 31)
%d – 一个月包含的天数(从01到31) - %D - same as %m/%d/%y
%D – 时间格式,与%m/%d/%y表示法相同 - %e - day of the month (1 to 31)
%e - 一个月包含的天数,数字前不包括0(从1到31) - %g - like %G, but without the century
%g – 与%G雷同,但除去“世纪[century]” - %G - 4-digit year corresponding to the ISO week number (see %V).
%G – 与ISO星期数相对应的4位数年份(见%V) - %h - same as %b
%h – 与%b相同 - %H - hour, using a 24-hour clock (00 to 23)
%H – 小时,使用24小时时钟(00到23) - %I - hour, using a 12-hour clock (01 to 12)
%I – 小时,使用12小时时钟(01到12) - %j - day of the year (001 to 366)
%j – 一年的天数(001到366) - %m - month (01 to 12)
%m – 月份(01到12) - %M - minute
%M – 分钟 - %n - newline character
%n – 换行符 - %p - either am or pm according to the given time value
%p – 与给定的时间值相对应的am或pm - %r - time in a.m. and p.m. notation
%r -用am或pm表示给定的时间 - %R - time in 24 hour notation
%R – 用24小时制表示的时间 - %S - second
%S – 秒 - %t - tab character
%t – tab键制表符 - %T - current time, equal to %H:%M:%S
%T – 当前时间,与“%H:%M:%S”组合相同 - %u - weekday as a number (1 to 7), Monday=1. Warning: In Sun Solaris Sunday=1
%u – 以数字形式表示星期几(1到7),Monday=1。提醒:在SUN Sloaris系统中,Sunday=1 - %U - week number of the current year, starting with the first Sunday as the first day of the first week
%U – 当今年份中包含的周的总数,以第一个星期日作为第一周的第一天 - %V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week
%V – 在当今年份中所包含的ISO 8601格式下的周的总数(01到53),week 1表示第一周,以周一作为每周的第一天 - %W - week number of the current year, starting with the first Monday as the first day of the first week
%W – 当前年份中包含的周的总数,以第一个星期一作为第一周的第一天 - %w - day of the week as a decimal, Sunday=0
%w – 以数字的形式表示星期几,Sunday[星期日]=0 - %x - preferred date representation without the time
%x – 选取除去时间[time]的日期[date] - %X - preferred time representation without the date
%X –选取除去日期[date]的时间[time] - %y - year without a century (range 00 to 99)
%y – 只显示包含年份的数字,不包含表示世纪的数字(00-99) - %Y - year including the century
%Y – 显示包含世纪数字的年份(即:四位数字表示的年份,如:1999,2001等) - %Z or %z - time zone or name or abbreviation
%Z或%z – 前者为时区名称;后者为时区名称的简称 - %% - a literal % character
%% - 输出“%”字符串 |
Tips and Notes
注意点
Note: This function is not implemented on Windows platforms.
注意:这个函数不能在Windows操作平台上执行。
Example
案例
Example of both strftime() and strptime():
strftime() 和 strptime()案例:
<?php
$format="%d/%m/%Y %H:%M:%S";
$strf=strftime($format);
echo("$strf");
print_r(strptime($strf,$format));
?> |
The output of the code above could be:
上述代码将输出下面的结果:
03/10/2005 13:23:44
Array
(
[tm_sec] => 44
[tm_min] => 23
[tm_hour] => 13
[tm_mday] => 3
[tm_mon] => 9
[tm_year] => 105
[tm_wday] => 0
[tm_yday] => 276
[unparsed] =>
) |