php 计算两个时间差

作者: Renew全栈工程师 | 来源:发表于2020-07-25 11:24 被阅读0次

官方代码

$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;

相关文章

网友评论

    本文标题:php 计算两个时间差

    本文链接:https://www.haomeiwen.com/subject/meuplktx.html