A-A+

php日期相加增加天数,月数的方法

2016年10月13日 编程技术 暂无评论

在做项目时需要做一个元素的过期时间,之前做过过期的天数相加时间,这次要直接加月数的,顺便就把所有php日期相加来整理一下吧,其实在php中,日期相加也是一件很简单的事情。

当前时间增加一天: eccho date('Y-m-d',strtotime("+1 day"))

当前时间增加一月: strtotime("+1 month")

当前时间增加一年: strtotime("+1 year")

当前时间增加一秒: strtotime("+1 seconds")

已有时间增加一天:

$d='2012-10-11';

eccho date('Y-m-d',strtotime("{$d} +1 day"));

更多的有

echo strtotime( 'yesterday ')

echo date( "Ymd ",strtotime( 'last week '));

我们只要将程式算法整合到项目中就可以了,把+1更改为自己需要的变量即可实际每次的时间都不一样了。

标签:

给我留言