如何以以下格式获取从今天起一周的日期:YYYY-MM-DD?
尝试:
date("Y-m-d", strtotime("+1 week"));
这将输出:
2015-12-31
如果今天是2015-12-24
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');
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."'n";
Charles预测中缺少一个,直接来自马的嘴,例如#1
将天、周、月添加到任何日期
$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");
for ($i=0 ; $i < 7 ;$i++)
{
$date[]=date('Y-m-d',strtotime("+{$i} day",time()));
}
print_r($date);