官方代码
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);
// %a will output the total number of days.
echo $interval->format('%a total days')."\n";
// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');
时间戳来计算
(strtotime('2020-1-1') - strtotime('2019-1-1')) / 60 / 60 / 24;
网友评论