使用DateTime::createFromFormat
如何计算与较晚时间之间的分钟$dt1
数差异$dt2
?$dt2
我试过$dt2 - $dt1
了,但这当然会产生一个error
。
<?php
date_default_timezone_set('America/New_York');
// $time1 will always be in HH:MM:SS MM/DD/YYYY format.
$time1 = "08:18:00 07/11/2013";
// $time2 will always be in MM/DD/YYYY HH:MM:SS format.
$time2 = "7/11/2013 9:11:00 AM";
$dt1 = DateTime::createFromFormat("H:i:s m/d/Y", $time1);
$dt2 = DateTime::createFromFormat("m/d/Y g:i:s a", $time2);
var_dump($dt1);
var_dump($dt2);
if ($dt1 < $dt2) echo "The first is earlier" . "\n";
?>