PHP开发PHP经验分享PHP实战

php 计算两个时间差

2020-07-25  本文已影响0人  Renew全栈工程师

官方代码

$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;
上一篇 下一篇

猜你喜欢

热点阅读