0
我正在使用DateTime :: diff()函数来回显当有10分钟差异时,剩余的分钟数。但是由于某种原因,微小的差别是一个。为什么DateTime:diff()关闭一分钟?
例如,如果我想要得到的11:20和11:30之间的区别,它会显示而不是左侧10
9分钟还使用了“现在”的时候,这是唯一的真实。如果我隐式输入“11:20”
$date = new DateTime("now", new DateTimeZone("America/New_York"));
然后它会显示10分钟的差异。
这是我写的代码的例子..
$closing_time = "11:30:00";
$date = new DateTime("now", new DateTimeZone("America/New_York"));
$time_now = $date->format("H:i:s");
echo $time_now. "<br>";
$time_remaining = $date->diff(new DateTime($closing_time,new DateTimeZone("America/New_York")));
$minutes = $time_remaining->i;
检查秒数... – 2014-11-04 16:32:23
按分钟计算时间时,您正舍入当前分钟的秒数。 – Flosculus 2014-11-04 16:32:24
@Flosculus感谢您的回复。我现在看到为什么会发生这种情况。我已经尝试过使用'ceil($分钟)',它仍然没有什么区别...我可以采取其他任何方式? – 2014-11-04 16:40:00