
strtotime
(PHP 4, PHP 5)
strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳
说明
int strtotime
( string $time
[, int $now = time()
] )
本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为
Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于
now 参数给出的时间,如果没有提供此参数则用系统当前时间。
本函数将使用 TZ 环境变量(如果有的话)来计算时间戳。自
PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在
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
在 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
现在发布 E_STRICT 和 E_NOTICE
时区错误。
5.0.2
在 PHP 5 中到 5.0.2 之前,”now”
和其它相对时间从今天午夜起错误计算了。这和正确从当前时间起计算的其它版本不同。
5.0.0
Microseconds began to be allowed, but they are ignored.
4.4.0
在 PHP 4.4 之前,”next” 被错误计算为 2。对此通常的解决方法是用 ” 1″。
范例
Example #1 strtotime() 例子
echo