从设定的日期中减少几分钟


Reduce some minute from a set date

我正在编写一个程序,其中设置了结束时间。假设今天的结束时间设置为"2015-08-23 22:15:00"。

现在,如果客户购买60分钟的服务,那么我想给他发送消息,让他在"2015-08-23 22:15:00"之前到达会场(-60分钟)意味着在"2015-08-23 21:15:00"。那么我怎样才能用上面的方法减去时间呢?

我有一个解决这个链接的方法。

运行正常
echo date('Y-m-d H:i:s', strtotime('-60 minutes'));

但不用于

echo date('2015-08-23 22:15:00', strtotime('-60 minutes'));

您使用日期的方式错误。这就是你想要的:

echo date('Y-m-d H:i:s', strtotime('2015-08-23 22:15:00') - 60 * 60);

我建议使用DateTime类并修改设置的时间:http://php.net/manual/de/datetime.modify.php

$date = new DateTime('2015-08-23 22:15:00');
$date->modify('-60 minutes'); // Or $date->modify('-1 hour');