来自http://php.net/manual/en/function.strtotime.php
<?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";
?>
Run Code Online (Sandbox Code Playgroud)
您可以添加第二个参数以使其添加到给定时间:
echo strtotime("+1 week",$timestamp)
Run Code Online (Sandbox Code Playgroud)
您可以使用PHP5 DateTime和DateInterval对象的组合.
$now = new DateTime();
// 30 days ago
$now->sub(new DateInterval("P30D");
// 1 week ago
$now->sub(new DateInterval("P1W");
// 2 years from now
$now->add(new DateInterval("P1Y");
Run Code Online (Sandbox Code Playgroud)
有关间隔代码列表,请参阅手册
检查一下strtotime()功能。http://php.net/manual/en/function.strtotime.php
另请注意,您可以使用第二个参数来指示何时开始。
strtotime('+1 day', mktime(0, 0, 0, 7, 1, 2000));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4098 次 |
| 最近记录: |