使用PHP计算两个日期之间相隔多少天

meShell · 2017年07月30日 · 阅读 647

面向对象风格:

<?php

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

过程式风格:

<?php

$january = date_create('2010-01-01');
$february = date_create('2010-02-01');
$interval = date_diff($january, $february);

// %a will output the total number of days.
echo $interval->format('%a total days')."\n";

关于作者

全栈工程师

文章被阅读 41.6k
获赞 3