当前时间
echo strtotime("+1 year");//返回时间戳, 如果要转换成一般时间格式还需要下面的函数
echo date('Y-m-d H:i:s', strtotime("+1 year"));
同理,不仅仅可以+year 还可以是天, 月日都可以的,如下代码:
<?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";
?>
指定时间
<?php
-
$t=1483967416;//指定时间戳
-
echo $dt=date('Y-m-d H:i:s',$t);//2017-01-09 21:10:16
-
/*方法一*/
-
echo date('Y-m-d H:i:s',$t+1*24*60*60);//指定时间戳+1天 2017-01-10 21:10:16
-
echo date('Y-m-d H:i:s',$t+365*24*60*60);//指定时间戳+1年 2018-01-09 21:10:16
-
/*方法二*/
-
//$dt是指定时间戳格式化后的日期
-
echo date('Y-m-d H:i:s',strtotime("$dt+1day"));//指定时间戳+1天 2017-01-10 21:10:16
-
echo date('Y-m-d H:i:s',strtotime("$dt+1year"));//指定时间戳+1年 2018-01-09 21:10:16
-
/*方法三*/
-
//$t是指定时间戳
-
echo date('Y-m-d H:i:s',strtotime("+1day",$t));//指定时间戳+1天 2017-01-10 21:10:16
-
echo date('Y-m-d H:i:s',strtotime("+1year",$t));//指定时间戳+1年 2018-01-09 21:10:16