php 日期格式 YYYY-MM-DD 减或从现在开始添加一周?

php
2022-08-30 13:29:30
today 22-05-2011 so it should be 29-05-2011? ( plus 1 week ) 
or
today 22-05-2011 so it should be 15-05-2011? ( minus 1 week ) 

感谢您的光临。

亚当·拉马丹


答案 1

使用 strtotime()

echo date('d-m-Y', strtotime("+1 week")); //1 week in the future
echo date('d-m-Y', strtotime("-1 week")); //1 week ago

答案 2

可以使用 DateTime 类执行日历计算。对于 exaple,要添加一周,您可以使用如下代码:

$date = new DateTime('22-05-2011');
$date->modify('+1 week');

推荐