close
http://php.net/manual/en/function.strtotime.php
int strtotime ( string $time [, int $now ] )
A date/time string. Valid formats are explained in Date and Time Formats.
The timestamp which is used as a base for the calculation of relative dates.
Return Values
Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1on failure.
Example #1 A strtotime() example
<?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";
?>
最近有個需求要用到這個,比如說要抓出四月1號到四月30號的時間區間,
EX:開始時間為:strtotime("2010-04-01");,但結束時間每個月的天數都不同,不能直接用30天的秒數去算,這時候就要用到strtotime("+1 month", strtotime("2010-04-01"));
在strtotime()中第一個參數位置,代入"+1 month",第二個參數(預設是now),代入"指定時間"即可。
這是個相當聰明的函式。
全站熱搜
留言列表