(PHP 4, PHP 5, PHP 7)
strtotime — ���κ��ַ���������ʱ����������Ϊ Unix ʱ���
$time
[, int $now
= time()
] ) : int
������Ԥ�ڽ���һ����������Ӣ�����ڸ�ʽ���ַ��������Խ������Ϊ
Unix ʱ������� January 1 1970 00:00:00 GMT �������������ֵ�����
now
����������ʱ�䣬���û���ṩ�˲�������ϵͳ��ǰʱ�䡣
��������ʹ�� TZ ��������������еĻ���������ʱ������� PHP 5.1.0 ���и����ķ���������ʱ���������е����ڣ�ʱ�亯�����˹����� date_default_timezone_get() ����ҳ������˵����
�ɹ���ʱ��������� FALSE
���� PHP 5.1.0
֮ǰ��������ʧ��ʱ���� -1��
��ÿ �ε�������/ʱ�亯��ʱ�����ʱ����Ч������� E_NOTICE
�������ʹ��ϵͳ�趨ֵ�� TZ
����������������� E_STRICT
�� E_WARNING
��Ϣ���μ�
date_default_timezone_set()��
�汾 | ˵�� |
---|---|
5.3.0 |
Prior to PHP 5.3.0, relative time formats supplied to the
time argument of strtotime()
such as this week, previous week,
last week, and next week were
interpreted to mean a 7 day period relative to the current date/time, rather
than a week period of Monday through Sunday.
|
5.3.0 |
�� PHP 5.3.0 ֮ǰ�� 24:00 ����һ����Ч�ĸ�ʽ������ strtotime() �᷵�� FALSE ��
|
5.2.7 | In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month would incorrectly add one week to the returned timestamp. This has been corrected in 5.2.7 and later versions. |
5.1.0 |
ʧ��ʱ���� FALSE �������� -1��
|
5.1.0 |
���ڷ��� |
5.0.2 | �� PHP 5 �е� 5.0.2 ֮ǰ��"now" ���������ʱ��ӽ�����ҹ���������ˡ������ȷ�ӵ�ǰʱ�������������汾��ͬ�� |
5.0.0 | Microseconds began to be allowed, but they are ignored. |
Example #1 strtotime() ����
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
Example #2 ʧ�ܼ��
<?php
$str = 'Not Good';
// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
echo "The string ($str) is bogus";
} else {
echo "$str == " . date('l dS of F Y h:i:s A', $timestamp);
}
?>
Note:
����������������λ���ֵĸ�ʽ������ֵ 0-69 ��ʾ 2000-2069��70-100 ��ʾ 1970-2000�� See the notes below for possible differences on 32bit systems (possible dates might end on 2038-01-19 03:14:07).
Note:
��Ч��ʱ���ͨ���� Fri, 13 Dec 1901 20:45:54 GMT �� Tue, 19 Jan 2038 03:14:07 GMT����Ӧ�� 32 λ�з�����������Сֵ�����ֵ����
PHP 5.1.0 ֮ǰ���������е�ƽ̨��֧�ָ���ʱ�������ô�ռǷ�Χ�ͱ�����Ϊ�������� Unix ��Ԫ������ζ���� 1970 �� 1 �� 1 ��֮ǰ�����ڽ��������� Windows��һЩ Linux �汾���Լ����������IJ���ϵͳ�С�
For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction.
Note:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-, the date string is parsed as y-m-d.
To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.
Note:
Using this function for mathematical operations is not advisable. It is better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later, or DateTime::modify() in PHP 5.2.