(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 锟斤拷锟叫革拷锟斤拷锟阶的凤拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟叫碉拷锟斤拷锟节o拷时锟戒函锟斤拷锟斤拷锟剿癸拷锟斤拷锟斤拷 date_default_timezone_get() 锟斤拷锟斤拷页锟斤拷锟斤拷锟斤拷说锟斤拷锟斤拷
time
锟斤拷锟斤拷/时锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷确锟斤拷式锟斤拷说锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟斤拷时锟斤拷锟绞�锟斤拷
now
锟斤拷锟斤拷锟斤拷锟姐返锟斤拷值锟斤拷时锟斤拷锟斤拷锟�
锟缴癸拷锟津返伙拷时锟斤拷锟斤拷锟斤拷锟斤拷蚍祷锟� 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 锟芥本锟斤拷锟皆硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥诧拷锟斤拷系统锟叫★拷
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.