在php中,如何计算10天后的日期?
假设在php中,如何计算10天后的日期?,php,date,strtotime,Php,Date,Strtotime,假设$start\u date=2017-12-13 我想知道10天后的日期 我尝试了这个strotime($start\u date+10天”),输出是1512946800您得到了时间戳作为值,现在您只需要将其格式化回最新状态 date("y-m-d HH:mi:ss", strtotime("$start_date +10 days")) date("Y-m-d", strtotime("$end_date -10 days")); //for minus 那就可以了 echo date
$start\u date=2017-12-13
我想知道10天后的日期
我尝试了这个
strotime($start\u date+10天”)
,输出是1512946800
您得到了时间戳作为值,现在您只需要将其格式化回最新状态
date("y-m-d HH:mi:ss", strtotime("$start_date +10 days"))
date("Y-m-d", strtotime("$end_date -10 days")); //for minus
那就可以了
echo date("Y-m-d", strtotime("+10 days", strtotime($start_date)));
你试着像上面那样。将“+10天”替换为所需的值,以获得所需的添加天数。使用phpstrotime()
函数获取10天之后的日期。strotime()
$start_date = "2017-12-13";
$future_date =strtotime("$start_date +10 days");//it will give the unix timestamp of the future date, now format it using date() function as
$future_date=date("Y-m-d H:i:s", $future_date);
检查此处的手册为什么不使用
输出
2017-12-23
使用DateTime更容易
$start_date = "2017-12-13";
$date = new DateTime($start_date);
echo $date->modify('+10 day')->format('Y-m-d');
$new_data=日期('Y-m-d',1512946800);谢谢巴迪@Farhan为什么所有的升级包?格式错误,yyyy-mm-dd HH:mi:ss
应该是Y-m-d H:i:s
@musashii这在这里很常见。人们对他们认为他们看到的东西投赞成票,而不是他们实际看到的东西。
$start_date = "2017-12-13";
$date = new DateTime($start_date);
echo $date->modify('+10 day')->format('Y-m-d');