Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP strtotime() Function

PHP strtotime() Function

PHP Date/Time PHP Date/Time Reference Manual

Example

Parse any string date/time description into a Unix timestamp:

Output result:


1516234088
1517408272
1517408272
968515200
1517494672
1518013072
1518200274
1517414400
1517155200

Definition and Usage

The strtotime() function parses any string date/time description into a Unix timestamp (the seconds since January 1 1970 00:00:00 GMT).

**Note:** If the year is given in two-digit format, values 0-69 map to 2000-2069 and values 70-100 map to 1970-2000.

**Note:** Be careful with dates in m/d/y or d-m-y formats: if the separator is a slash (/), the American m/d/y format is assumed. If the separator is a dash (-) or a dot (.), the European d-m-y format is assumed. To avoid potential errors, you should use the YYYY-MM-DD format or the date_create_from_format() function whenever possible.

Syntax


int strtotime ( string $time [, int $now = time() ] )
Parameters Description
time Required. Specifies a date/time string.
now Optional. Specifies the timestamp used to calculate the return value. If omitted, the current time is used.

Technical Details

Return Value: Returns a timestamp on success, or FALSE on failure.
PHP Version: 4+
Changelog: PHP 5.3.0: Relative time formats such as this week, previous week, last week, and next week now define a week as Monday through Sunday, rather than a span of 7 days relative to the current date/time.
 PHP 5.3.0: 现在 24:00 是有效的格式。       
 PHP 5.2.7:在这之前的版本中,如果请求一个月中某个给定日期且该日期刚好是该月的第一天,则会错误地把增加一个星期到返回的时间戳中,这点现在已经得到更正。       
 PHP 5.1.0:如果失败则返回 FALSE(在这之前的版本则返回 -1),并增加了 E_STRICT 和 E_NOTICE 时区错误。       
 PHP 5.0.2:现在正确计算 "now" 和其他相对时间是以当前时间为准,而不是以今天午夜的时间为准。       
 PHP 5.0.0:允许微秒(但微秒数通常被忽略)。 |

PHP Date/Time PHP Date/Time Reference Manual