如何从今天起一周后以下列格式获取日期:YYYY-MM-DD?
感谢。
答案 0 :(得分:90)
尝试:
date("Y-m-d", strtotime("+1 week"));
这将输出:
2015-12-31
如果今天是2015-12-24
答案 1 :(得分:18)
正如Charles的预测错误,这是一个PHP 5.3+示例:
$now = new DateTime;
$interval = new DateInterval('P1W')
$next_week = $now->add($interval);
echo $next_week->format('Y-m-d');
或稍微紧凑的形式:
$now = new DateTime();
echo $now->add(new DateInterval('P1W'))->format('Y-m-d');
答案 2 :(得分:7)
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
查尔斯预测遗失了一个人,straight from the horses mouth, example #1
答案 3 :(得分:7)
将天,周,月添加到任何日期
$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");
答案 4 :(得分:1)
for ($i=0 ; $i < 7 ;$i++)
{
$date[]=date('Y-m-d',strtotime("+{$i} day",time()));
}
print_r($date);