(PHP 4, PHP 5, PHP 7)
strftime — �����������ø�ʽ������ʱ�䣯����
$format
[, int $timestamp
= time()
] ) : string
�����ø����ĸ�ʽ�ִ��Ը����� timestamp
���и�ʽ�������ַ��������û�и���ʱ������õ�ǰ�ı���ʱ�䡣�·ݺ����ڼ��Լ������������йص��ַ���д������
setlocale() �趨�ĵ�ǰ�������йء�
���ܲ������е�ת����Ƕ��� C ���ļ�֧�֣���������� PHP �� strftime() Ҳ��֧�֡����⣬�������е�ƽ̨��֧�ָ���ʱ�����������ڵķ�Χ�������ڲ����� Unix ��Ԫ������ζ������ %e, %T��%R �� %D�����ܸ��ࣩ�Լ����� Jan 1, 1970 ��ʱ���� Windows��һЩ Linux ���а汾���Լ�������������ϵͳ����Ч������ Windows ϵͳ����֧�ֵ�ת����ǿ��� » MSDN ��վ�ҵ���
format
��ʽ |
���� | ����ֵʾ�� |
---|---|---|
�� | --- | --- |
%a | ��ǰ�������ڼ��ļ�д | Sun �� Sat |
%A | ��ǰ�������ڼ���ȫ�� | Sunday �� Saturday |
%d | �·��еĵڼ��죬ʮ�������֣���Χ�� 01 �� 31�� | 01 �� 31 |
%e | �·��еĵڼ��죬ʮ�������֣�һλ������ǰ�����һ���ո�Χ�� ' 1' �� '31'�� �� Windows ����δ������ʵ�֡�������Ϣ���·��� | 1 �� 31 |
%j | ����еĵڼ��죬��ǰ�������λʮ����������Χ�� 001 �� 366�� | 001 �� 366 |
%u | ���� ISO-8601 ���ڼ���ʮ��������� [1,7]��1 ��ʾ����һ | 1 (����һ) �� 7 (������) |
%w | �����еĵڼ��죬������Ϊ 0 | 0 (������) �� 6 (������) |
�� | --- | --- |
%U | ����ĵڼ��ܣ��ӵ�һ�ܵĵ�һ����������Ϊ��һ�쿪ʼ | 13 (for the 13th full week of the year) |
%V | %V - ����ڼ��ܵ� ISO-8601:1988 ��ʽ����Χ�� 01 �� 53���� 1 ���DZ����һ�����ٻ��� 4 ������ڣ�����һ��Ϊÿ�ܵĵ�һ�졣���� %G ���� %g ��Ϊָ��ʱ�����Ӧ�����������ɡ��� | 01 �� 53 (where 53 accounts for an overlapping week) |
%W | ����ĵڼ��������ӵ�һ�ܵĵ�һ������һ��Ϊ��һ�쿪ʼ | 46 (for the 46th week of the year beginning with a Monday) |
�� | --- | --- |
%b | ��ǰ�����·ݵļ�д | Jan �� Dec |
%B | ��ǰ�����·ݵ�ȫ�� | January �� December |
%h | ��ǰ�����·ݵļ�д��%b �ı����� | Jan �� Dec |
%m | ��λ�����·� | 01 (��һ�·�) �� 12 (��ʮ���·�) |
�� | --- | --- |
%C | ��λ����ʾ���ͣ���ݳ��� 100���س������� | 19 �� 20 ���� |
%g | 2 λ������ݣ����� ISO-8601:1988 ���������μ� %V������ %V �ĸ�ʽ��ֵһ����ֻ������� ISO ����������ǰһ����ߺ�һ�꣬��ʹ����һ�ꡣ | ���磺2009��1��6����һ���� 09�� |
%G | %g ��������λ���汾 | ���磺2009��1��3����һ���� 2008. |
%y | ��λ����ʾ��� | ���磺 09 �� 2009��79 �� 1979 |
%Y | ��λ����ʾ��� | ���磺 2038 |
ʱ�� | --- | --- |
%H | �� 24 Сʱ��ʽ��ʾ��λСʱ�� | 00 �� 23 |
%I | �� 12 Сʱ��ʽ��ʾ��λСʱ�� | 01 �� 12 |
%l��'L' ��Сд�� | �� 12 Сʱ��ʽ��ʾСʱ������������ǰ���ո� | 1 �� 12 |
%M | ��λ�ķ����� | 00 �� 59 |
%p | ָ��ʱ��Ĵ�д "AM" �� "PM" | ���磺 00:31 �� AM ��22:23 ��PM |
%P | ָ��ʱ���Сд "am" �� "pm" | ���磺00:31 �� am ��22:23 ��pm |
%r | �� "%I:%M:%S %p" һ�� | ���磺 21:34:17 �� 09:34:17 PM |
%R | �� "%H:%M" һ�� | ���磺 12:35 AM �� 00:35��4:44 PM �� 16:44 |
%S | ��λ���ֱ�ʾ�� | 00 �� 59 |
%T | �� "%H:%M:%S" һ�� | ���磺 09:34:17 PM �� 21:34:17 |
%X | ��ǰ������ѡ��ʱ���ʾ�������������� | ���磺 03:59:16 �� 15:59:16 |
%z | �� UTC ��ʱ��ƫ�� �� ��д���ɲ���ϵͳ������ | ���磺 ����ʱ���� -0500 �� EST |
%Z | %z û�и����� UTC ��ʱ��ƫ�� �� ��д���ɲ���ϵͳ������ | ���磺 -0500 �� EST �Ƕ���ʱ�� |
ʱ������ڴ� | --- | --- |
%c | ��ǰ������ѡ������ʱ���� | ���磺 2009 �� 2 �� 5 ������ 12:45:10 �� Tue Feb 5 00:45:10 2009 |
%D | �� "%m/%d/%y" һ�� | ���磺 2009 �� 2 �� 5 ���� 02/05/09 |
%F | Same as "%Y-%m-%d" (commonly used in database datestamps) | ���磺2009 �� 2 �� 5 ���� 2009-02-05 |
%s | Unix��Ԫ��ʱ������� time() ����һ���� | ���磺 1979 �� 9 �� 10 ������ 8 �� 40 �� 00 ���� 305815200 |
%x | ��ǰ������ѡ��ʱ���ʾ����������ʱ�� | ���磺 2009 �� 2 �� 5 ���� 02/05/09 |
���� | --- | --- |
%n | ���з�("\n") | --- |
%t | Tab �ַ�("\t") | --- |
%% | �����ϵİٷ��ַ�("%") | --- |
�������������� 1023 ���ַ���
���� ISO 9889:1999����ǰ�� C ������ȷָ��һ�ܴ�����һ��ʼ������ Sun Solaris ��һ���ƺ��������쿪ʼ����Ϊ 1������ %u �Ľ��Ҳ������ֲ���������һ����
����� Windows����������� %e ���η����η�������֧�� Windows�� Ϊ�˵õ����ֵ������ %#d ���η������档����˵�������дһ����ƽ̨֧�ֵĺ�����
����� Mac OS X����������� %P ���η�������֧�� Mac OS X��
timestamp
��ѡ�� timestamp
������һ�� integer �� Unix
ʱ�������δָ��������ֵĬ��Ϊ��ǰ����ʱ�䡣Ҳ����˵����ֵĬ��Ϊ
time() �ķ���ֵ��
����ָ���� timestamp
��δ���� timestamp ��ʹ�õ�ǰ����ʱ�䣬
���� format
��ʽ�����ַ���
�·ݡ���������������������ص��ַ������� setlocale() ���õĵ�ǰ�������á�
��ÿ �ε�������/ʱ�亯��ʱ�����ʱ����Ч������� E_NOTICE
�������ʹ��ϵͳ�趨ֵ�� TZ
����������������� E_STRICT
�� E_WARNING
��Ϣ���μ�
date_default_timezone_set()��
������������� C �⣬����һЩת����Dz�����֧�֡�
�� Windows �ϣ�ʹ��δ֪��ת����ǽ�����
5 E_WARNING
��Ϣ�������� FALSE
��
�������IJ���ϵͳ�ϣ�����ܲ��ܵõ��κ� E_WARNING
��Ϣ��
���ҿ������δ��ת����ת����ǡ�
�汾 | ˵�� |
---|---|
5.1.0 |
���ڷ��� |
������ϵͳ�ﰲװ�˸��Ե����Ի����������ܹ��������С�
Example #1 strftime() ���������
<?php
setlocale(LC_TIME, "C");
echo strftime("%A");
setlocale(LC_TIME, "fi_FI");
echo strftime(" in Finnish is %A,");
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
setlocale(LC_TIME, "de_DE");
echo strftime(" in German %A.\n");
?>
Example #2 ISO 8601:1988 week number example
<?php
/* December 2002 / January 2003
ISOWk M Tu W Thu F Sa Su
----- ----------------------------
51 16 17 18 19 20 21 22
52 23 24 25 26 27 28 29
1 30 31 1 2 3 4 5
2 6 7 8 9 10 11 12
3 13 14 15 16 17 18 19 */
// ����� 12/28/2002 - %V,%G,%Y = 52,2002,2002
echo "12/28/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y", strtotime("12/28/2002")) . "\n";
// ����� 12/30/2002 - %V,%G,%Y = 1,2003,2002
echo "12/30/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y", strtotime("12/30/2002")) . "\n";
// ����� 1/3/2003 - %V,%G,%Y = 1,2003,2003
echo "1/3/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2003")) . "\n";
// ����� 1/10/2003 - %V,%G,%Y = 2,2003,2003
echo "1/10/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/10/2003")) . "\n";
/* December 2004 / January 2005
ISOWk M Tu W Thu F Sa Su
----- ----------------------------
51 13 14 15 16 17 18 19
52 20 21 22 23 24 25 26
53 27 28 29 30 31 1 2
1 3 4 5 6 7 8 9
2 10 11 12 13 14 15 16 */
// ����� 12/23/2004 - %V,%G,%Y = 52,2004,2004
echo "12/23/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/23/2004")) . "\n";
// ����� 12/31/2004 - %V,%G,%Y = 53,2004,2004
echo "12/31/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/31/2004")) . "\n";
// ����� 1/2/2005 - %V,%G,%Y = 53,2004,2005
echo "1/2/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/2/2005")) . "\n";
// ����� 1/3/2005 - %V,%G,%Y = 1,2005,2005
echo "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n";
?>
Example #3 %e ������ƽ̨���ݵ�����
<?php
// Jan 1: results in: '%e%1%' (%%, e, %%, %e, %%)
$format = '%%e%%%e%%';
// Check for Windows to find and replace the %e
// modifier correctly
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '</refsect1>%#d', $format);
}
echo strftime($format);
?>
Example #4 ��ʾ������֪��δ֪�ĸ�ʽ
<?php
// Describe the formats.
$strftimeFormats = array(
'A' => 'A full textual representation of the day',
'B' => 'Full month name, based on the locale',
'C' => 'Two digit representation of the century (year divided by 100, truncated to an integer)',
'D' => 'Same as "%m/%d/%y"',
'E' => '',
'F' => 'Same as "%Y-%m-%d"',
'G' => 'The full four-digit version of %g',
'H' => 'Two digit representation of the hour in 24-hour format',
'I' => 'Two digit representation of the hour in 12-hour format',
'J' => '',
'K' => '',
'L' => '',
'M' => 'Two digit representation of the minute',
'N' => '',
'O' => '',
'P' => 'lower-case "am" or "pm" based on the given time',
'Q' => '',
'R' => 'Same as "%H:%M"',
'S' => 'Two digit representation of the second',
'T' => 'Same as "%H:%M:%S"',
'U' => 'Week number of the given year, starting with the first Sunday as the first week',
'V' => 'ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week',
'W' => 'A numeric representation of the week of the year, starting with the first Monday as the first week',
'X' => 'Preferred time representation based on locale, without the date',
'Y' => 'Four digit representation for the year',
'Z' => 'The time zone offset/abbreviation option NOT given by %z (depends on operating system)',
'a' => 'An abbreviated textual representation of the day',
'b' => 'Abbreviated month name, based on the locale',
'c' => 'Preferred date and time stamp based on local',
'd' => 'Two-digit day of the month (with leading zeros)',
'e' => 'Day of the month, with a space preceding single digits',
'f' => '',
'g' => 'Two digit representation of the year going by ISO-8601:1988 standards (see %V)',
'h' => 'Abbreviated month name, based on the locale (an alias of %b)',
'i' => '',
'j' => 'Day of the year, 3 digits with leading zeros',
'k' => '',
'l' => 'Hour in 12-hour format, with a space preceeding single digits',
'm' => 'Two digit representation of the month',
'n' => 'A newline character ("\n")',
'o' => '',
'p' => 'UPPER-CASE "AM" or "PM" based on the given time',
'q' => '',
'r' => 'Same as "%I:%M:%S %p"',
's' => 'Unix Epoch Time timestamp',
't' => 'A Tab character ("\t")',
'u' => 'ISO-8601 numeric representation of the day of the week',
'v' => '',
'w' => 'Numeric representation of the day of the week',
'x' => 'Preferred date representation based on locale, without the time',
'y' => 'Two digit representation of the year',
'z' => 'Either the time zone offset from UTC or the abbreviation (depends on operating system)',
'%' => 'A literal percentage character ("%")',
);
// Results.
$strftimeValues = array();
// Evaluate the formats whilst suppressing any errors.
foreach($strftimeFormats as $format => $description){
if (False !== ($value = @strftime("%{$format}"))){
$strftimeValues[$format] = $value;
}
}
// Find the longest value.
$maxValueLength = 2 + max(array_map('strlen', $strftimeValues));
// Report known formats.
foreach($strftimeValues as $format => $value){
echo "Known format : '{$format}' = ", str_pad("'{$value}'", $maxValueLength), " ( {$strftimeFormats[$format]} )\n";
}
// Report unknown formats.
foreach(array_diff_key($strftimeFormats, $strftimeValues) as $format => $description){
echo "Unknown format : '{$format}' ", str_pad(' ', $maxValueLength), ($description ? " ( {$description} )" : ''), "\n";
}
?>
�������̵���������ڣ�
Known format : 'A' = 'Friday' ( A full textual representation of the day ) Known format : 'B' = 'December' ( Full month name, based on the locale ) Known format : 'H' = '11' ( Two digit representation of the hour in 24-hour format ) Known format : 'I' = '11' ( Two digit representation of the hour in 12-hour format ) Known format : 'M' = '24' ( Two digit representation of the minute ) Known format : 'S' = '44' ( Two digit representation of the second ) Known format : 'U' = '48' ( Week number of the given year, starting with the first Sunday as the first week ) Known format : 'W' = '48' ( A numeric representation of the week of the year, starting with the first Monday as the first week ) Known format : 'X' = '11:24:44' ( Preferred time representation based on locale, without the date ) Known format : 'Y' = '2010' ( Four digit representation for the year ) Known format : 'Z' = 'GMT Standard Time' ( The time zone offset/abbreviation option NOT given by %z (depends on operating system) ) Known format : 'a' = 'Fri' ( An abbreviated textual representation of the day ) Known format : 'b' = 'Dec' ( Abbreviated month name, based on the locale ) Known format : 'c' = '12/03/10 11:24:44' ( Preferred date and time stamp based on local ) Known format : 'd' = '03' ( Two-digit day of the month (with leading zeros) ) Known format : 'j' = '337' ( Day of the year, 3 digits with leading zeros ) Known format : 'm' = '12' ( Two digit representation of the month ) Known format : 'p' = 'AM' ( UPPER-CASE "AM" or "PM" based on the given time ) Known format : 'w' = '5' ( Numeric representation of the day of the week ) Known format : 'x' = '12/03/10' ( Preferred date representation based on locale, without the time ) Known format : 'y' = '10' ( Two digit representation of the year ) Known format : 'z' = 'GMT Standard Time' ( Either the time zone offset from UTC or the abbreviation (depends on operating system) ) Known format : '%' = '%' ( A literal percentage character ("%") ) Unknown format : 'C' ( Two digit representation of the century (year divided by 100, truncated to an integer) ) Unknown format : 'D' ( Same as "%m/%d/%y" ) Unknown format : 'E' Unknown format : 'F' ( Same as "%Y-%m-%d" ) Unknown format : 'G' ( The full four-digit version of %g ) Unknown format : 'J' Unknown format : 'K' Unknown format : 'L' Unknown format : 'N' Unknown format : 'O' Unknown format : 'P' ( lower-case "am" or "pm" based on the given time ) Unknown format : 'Q' Unknown format : 'R' ( Same as "%H:%M" ) Unknown format : 'T' ( Same as "%H:%M:%S" ) Unknown format : 'V' ( ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week ) Unknown format : 'e' ( Day of the month, with a space preceding single digits ) Unknown format : 'f' Unknown format : 'g' ( Two digit representation of the year going by ISO-8601:1988 standards (see %V) ) Unknown format : 'h' ( Abbreviated month name, based on the locale (an alias of %b) ) Unknown format : 'i' Unknown format : 'k' Unknown format : 'l' ( Hour in 12-hour format, with a space preceeding single digits ) Unknown format : 'n' ( A newline character ("\n") ) Unknown format : 'o' Unknown format : 'q' Unknown format : 'r' ( Same as "%I:%M:%S %p" ) Unknown format : 's' ( Unix Epoch Time timestamp ) Unknown format : 't' ( A Tab character ("\t") ) Unknown format : 'u' ( ISO-8601 numeric representation of the day of the week ) Unknown format : 'v'
Note: %G �� %V��������ֱ��ϵͳδ�ܳ����⣬���� ISO 8601:1988 �����������ܵó�δԤ�ڵĽ����������� %V �����µ����ӡ�