php获取指定日期

2017-07-28  本文已影响0人  凌乱秋天
/**
 php获取指定日期的前一天,前一月,前一年日期
*/

$time = "2017-7-28";        //特定时间

echo "前一天的日期为". date("Y-m-d",strtotime("-1 days",$time))."</br>";

echo "前一月的日期为". date("Y-m-d",strtotime("-1 months",$time))."</br>";

echo "前一年的日期为". date("Y-m-d",strtotime("-1 years",$time))."</br>";


//如果是后一天,后一年,后一个月的日期

echo "后一天的日期为". date("Y-m-d",strtotime("+1 days",$time))."</br>";

echo "后一月的日期为". date("Y-m-d",strtotime("+1 months",$time))."</br>";

echo "后一年的日期为". date("Y-m-d",strtotime("+1 years",$time))."</br>";

//如果不是1,就把+1或者-1换成+n或者-n就可以了。
上一篇 下一篇

猜你喜欢

热点阅读