【发布时间】:2017-12-15 10:29:38
【问题描述】:
假设$start_date = 2017-12-13。
我想知道 10 天后的日期。
我试过这个strtotime("$start_date +10 days"),输出是1512946800
【问题讨论】:
-
$new_data = date('Y-m-d',1512946800);
-
谢谢好友@Farhan
假设$start_date = 2017-12-13。
我想知道 10 天后的日期。
我试过这个strtotime("$start_date +10 days"),输出是1512946800
【问题讨论】:
您将时间戳作为值,现在您只需将其格式化回日期即可。
date("y-m-d HH:mi:ss", strtotime("$start_date +10 days"))
date("Y-m-d", strtotime("$end_date -10 days")); //for minus
这应该会解决它。
【讨论】:
yyyy-mm-dd HH:mi:ss应该是Y-m-d H:i:s
echo date("Y-m-d", strtotime("+10 days", strtotime($start_date)));
你尝试像上面那样。将“+10 天”替换为您想要的值,以获得您希望添加的天数。
【讨论】:
使用 php strtotime() 函数获取 10 天后的日期。 strtotime() 函数给出未来日期的 unix 时间戳,现在使用 date() 函数将其格式化为
$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);
在此处查看手册php strtotime()
【讨论】:
使用 DateTime 更容易
$start_date = "2017-12-13";
$date = new DateTime($start_date);
echo $date->modify('+10 day')->format('Y-m-d');
【讨论】: