php中如何让月份加1

2025-05-18 16:17:56
推荐回答(3个)
回答(1):

可以直接在输出的日期上加上一个月

echo date('Y-m-d',strtotime('+1 month'));

也可以单独给月份加上一个月

echo date('Y').'-'.(date('m')+1).'-'.date('d');

回答(2):

利用strtotime 来实现, 返回的是Unix 时间戳, strftime 第二个参数也是 Unix 时间戳
strtotime('-1 month', time()) // 上个月
strtotime('+1 month', time()) // 下个月
strtotime('+2 month', time()) // 下两个月
strtotime('+5 month', time()) // 下五个月

strtotime('-1 day', time()) // 昨天
strtotime('+1 day', time()) // 明天
strtotime('+2 day', time()) // 后天

strtotime('+1 week', time()) // 下个星期
strtotime('+2 week', time()) // 下两星期

strtotime('now') // 当前时间

更详细的参考 PHP 手册

回答(3):

重写日期,加一个可以自定义日期的