php 当前日期加一天和指定日期加一天、或月、年等

1.给当前时间加一天?一小时

echo "今天:",date('Y-m-d H:i:s'),"<br>";

加
echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));


减
echo "明天:",date('Y-m-d H:i:s',strtotime('-1 day'));

2.同理加一年,一小时,一分钟 ,一月 

echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));

echo "明天:",date('Y-m-d H:i:s',strtotime('+1 hour'));

echo "明天:",date('Y-m-d H:i:s',strtotime('+1 minute'));

echo "明天:",date('Y-m-d H:i:s',strtotime('+1 mouth'));

这里+1 day可以修改参数1为任何想需要的数 day也可以改成year(年),month(月),hour(小时)minute(分),second(秒)如:

date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute");

3.给指定时间加一天?一小时?.

echo   date("Y-m-d",strtotime("+1 month",strtotime("2012-02-04")));

echo   date("Y-m-d",strtotime("+1 week",strtotime("2011-02-04")));

echo   date("Y-m-d",strtotime("+1 day",strtotime("2011-02-04")));

猜你喜欢

转载自blog.csdn.net/qq_32450471/article/details/131277567
今日推荐