我试图比较两个日期 - 检查他们之间在几分钟之间的差异。 我的代码是:如何从dateTime对象获取日期
$first_date = new DateTime($token->created_at);
$first_date->format('Y-m-d H:i:s');
$second_date = new DateTime();
$second_date->format('Y-m-d H:i:s');
$difference = $first_date->diff($second_date);
$time_diff = $difference->format("%i");
var_dump($first_date);
//I get this object
object(DateTime)#552 (3) {
["date"]=>
string(26) "2016-04-21 10:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
如何从DateTime对象约会,所以我应该比较两个日期,检查差异悫他们。 谢谢。
如果两个日期之间的差异是例如 - 2天0小时5分钟 - >将会是这个代码的工作,它应该是'''$ difference_in_hours> 1''',因为它应该? –
@mistery_girl正确。 '$ difference_in_hours'从字面上看已经过去了数小时。如果你之间有2天,那么$ difference_in_hours将等于48(意思是48小时)。 – Webeng
感谢您的解释。 :))) –