[英]Get the date of one week from today
如何以以下格式获取从今天起一周的日期:YYYY-MM-DD?
Try:尝试:
date("Y-m-d", strtotime("+1 week"));
This will output:这将输出:
2015-12-31
If today is 2015-12-24如果今天是 2015-12-24
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');
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");
<?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
for ($i=0 ; $i < 7 ;$i++)
{
$date[]=date('Y-m-d',strtotime("+{$i} day",time()));
}
print_r($date);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.