php 日期格式 YYYY-MM-DD 从现在起减去或添加一周?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6086389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:19:00 来源:igfitidea点击:
php date format YYYY-MM-DD minus or add one week from now?
提问by Adam Ramadhan
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 )
thanks for looking in.
感谢您的关注。
Adam Ramadhan
亚当·拉马丹
回答by JohnP
Use 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
回答by Luká? Lalinsky
回答by John Green
回答by swathi_sri
In case If you dint want to hard code today's date you can use Carbon class methods of php.
如果你不想硬编码今天的日期,你可以使用 php 的 Carbon 类方法。
Carbon::now()->subWeek(1);
Carbon::now()->addWeek(1);