php 获取从今天起一周的日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5628735/
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
Get the date of one week from today
提问by santa
How do I get the date, one week from today, in the following format: YYYY-MM-DD ?
如何以以下格式获取从今天起一周的日期:YYYY-MM-DD?
回答by Joel
Try:
尝试:
date("Y-m-d", strtotime("+1 week"));
This will output:
这将输出:
2015-12-31
If today is 2015-12-24
如果今天是 2015-12-24
回答by Marc B
Just so Charles' prediction is wrong, here's a PHP 5.3+ example:
只是查尔斯的预测是错误的,这是一个 PHP 5.3+ 示例:
$now = new DateTime;
$interval = new DateInterval('P1W')
$next_week = $now->add($interval);
echo $next_week->format('Y-m-d');
or in slightly more compact form:
或者稍微更紧凑的形式:
$now = new DateTime();
echo $now->add(new DateInterval('P1W'))->format('Y-m-d');
回答by open-ecommerce.org
adding days, weeks, months to any date
将天、周、月添加到任何日期
$date = date("Y-m-d");// current date
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");
回答by Captain Giraffe
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
One missing from Charles prediction, straight from the horses mouth, example #1
查尔斯预测中缺少一个,直接来自马口,示例#1