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

2,428次阅读

共计 395 个字符,预计需要花费 1 分钟才能阅读完成。

面向对象风格:

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

正文完
 0
Blood.Cold
版权声明:本站原创文章,由 Blood.Cold 于2019-06-03发表,共计395字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。