我有以下代码,但这给了我全部数字:
<?php
$datetime1 = new DateTime('2009-10-11 00:00:00');
$datetime2 = new DateTime('2009-10-11 00:00:10');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
?>
如何计算天数并显示小数点?在上面的示例中,有10秒的差异,如何让它显示0.000000天?
答案 0 :(得分:1)
为什么不使用strtotime?
$oneDay = 24 * 60 * 60;
$datetime1 = strtotime('2009-10-11 00:00:00');
$datetime2 = strtotime('2009-10-11 00:00:10');
$interval = $datetime2 - $datetime1; // seconds
$days = $interval / $oneDay; // fractions of days