php 添加分钟到现在

php add mins to date

$orderDate = date('d/m/Y H:i:s', strtotime($result[$x]['date_modified']) );
echo "<br>".$orderDate;
$endTime =date('d/m/Y H:i:s',strtotime('+10 minutes', $orderDate));
echo "<br>".date('d/m/Y H:i:s', $endTime);

打印为

28/05/2018 09:27:45 - 这是正确的

Notice: A non well formed numeric value encountered in C:\xampp5.5\htdocs\php\index.php on line 4166

Notice: A non well formed numeric value encountered in C:\xampp5.5\htdocs\php\index.php on line 4167

01/01/1970 12:00:01 - 为什么这不起作用?

strtotime 函数不适用于一些日期格式,d/m/Y 就是其中一种格式。为了正确操作日期和时间,一种推荐的格式是 MySQL 日期格式,即 YYYY-mm-dd 并进一步处理它。

进一步阅读:The strtotime documentation reads

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

使用DateTime::createFromFormat接受所有类型的日期和时间格式

$dt = DateTime::createFromFormat('d/m/Y h:i:s', '28/05/2018 09:27:45');
$dt->add(new DateInterval('PT10M'));
echo $dt->format('d/m/Y h:i:s');

Live Demo

$orderDateTimestamp = strtotime($result[$x]['date_modified']);
$endDateTimeStamp = strtotime('+10 minutes', $orderDateTimestamp);
$orderDate = date('d/m/Y H:i:s', $orderDateTimestamp);
$endDate = date('d/m/Y H:i:s', $endDateTimeStamp);
echo $orderDate.'<br>'.$endDate;

strtotime 期望第二个参数是一个整数(时间戳)。此外,它不接受所有格式作为字符串源,例如 d/m/Y(还要检查 $result[$x]['date_modified'] 的格式,如果它来自 MySql 结果集,你不应该有问题,因为它是 Y-m-d H:i:s) 。 所以用这个解决方案纠正它,它应该工作