PHP 时间和日期
————主要讲解一些函数的含义(因为我自己看的时候有点歧义,还是花了点时间搞懂的)
int strtotime ( string $time
[, int $now
= time() ] );
time
日期/时间字符串。正确格式的说明详见 日期与时间格式。
now
用来计算返回值的时间戳。
官方文档是这么解释的。更清晰的理解:
time是一个相对值,相对于now的一个时间差。
没有 now参数时, now默认为当前时间戳(离unix标准时间的秒数)。
设置了now 自然就用设置的now值。
返回值是,
now+time 也就是现在时间(或者你设置的时间) + 相对时间得到的时间
和 unix标准时间
的差(时间戳)
例子:
<?php
echo(strtotime("now") . "<br>");
echo(strtotime("15 October 1980") . "<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"));
?>
默认now均为当前时间,注意第二行,直接给出了一个日期(其他均为相对时间),那么这个日期就直接当作要和
unix标准时间计算的那个值。