晓夏

北漂的女孩

Good Luck To You!

php根据当前时间算出其他时间

浏览量:503

#方法一:用strtotime()
//当前时间为2015-10-26
//3天后;
$d=strtotime('3 days');
echo '3天后'.date('Y-m-d',$d)."<br />";
//2015-10-29


//3天前:
$d=strtotime('-3 days');
echo '3天前'.date('Y-m-d',$d)."<br />";
//2015-10-23

//一个月前:
$d=strtotime('-1 months');
echo '一个月前'.date('Y-m-d',$d)."<br />";
//2015-09-26

//2个月后:
$d=strtotime('2 months');
echo '二个月后'.date('Y-m-d',$d)."<br />";
//2015-12-26

//1年前:
$d=strtotime('-1 years');
echo '1年前'.date('Y-m-d',$d)."<br />";
//2014-10-26


//2小时前:
$d=strtotime('-2 hours');
echo '目前:'.date('Y-m-d H:i:s',time()).',2小时前'.date('Y-m-d H:i:s',$d)."<br />";
//目前:2015-10-26 10:50:13,2小时前2015-10-26 08:50:13

神回复

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。