PHP strtotime () function
PHP Date / Time Reference Manual
Examples
The English text date time resolve to Unix timestamp:
<?php
echo(strtotime("now") . "<br>");
echo(strtotime("3 October 2005") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
?>
echo(strtotime("now") . "<br>");
echo(strtotime("3 October 2005") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
?>
Running instance »
Definition and Usage
strtotime () function to the date or time of any English text description of resolve to Unix timestamp (seconds since January 1 1970 00:00:00 GMT starting).
Note: If youuse two digits to indicate the year format, the value is mapped to 2000-2069 0-69, 70-100 value is mapped to 1970-2000.
Note: Please note the date m / d / y or dmy format, if the delimiter is a slash (/), the Americas using m / d / y format. If the separator is a dash (-) (.) Or a point, use European dmy format. To avoid potential errors, you should try to use YYYY-MM-DD format, or use date_create_from_format () function.
grammar
strtotime( time,now);
参数 | 描述 |
---|---|
time | 必需。规定日期/时间字符串。 |
now | 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。 |
technical details
return value: | Returns a timestamp on success, on failure returns FALSE. |
---|---|
PHP version: | 4+ |
Update log: | PHP 5.3.0: now relative time format, such as this week, the week before last week, next week, a predetermined one week from Monday to Sunday, instead of back and forth relative to the current date / time of 7 days. PHP 5.3.0: 24:00 now is a valid format. PHP 5.2.7: Prior to this version, if the request for a month in a given date and the date is just the first day of the month, it will increase the time stamp mistakenly returned a week, this point has now been corrected. PHP 5.1.0: If it fails it returns FALSE (before this version returns -1), and increases the E_STRICT and E_NOTICE time zone errors. PHP 5.0.2: now calculated correctly "now" and other relative times based on the current time, instead of the midnight of the time. PHP 5.0.0: Allow microseconds (microseconds but often overlooked). |
PHP Date / Time Reference Manual