我想知道如何提取确切的夜晚数量.我尝试通过两种方式实现这一目标但不起作用.它返回20晚但实际上是21晚(3月有31天)
$startTimeStamp = strtotime("14-03-2017");
$endTimeStamp = strtotime("04-04-2017");
$timeDiff = abs($endTimeStamp - $startTimeStamp);
$numberDays = $timeDiff/86400; // 86400 seconds in one day
$numberDays = intval($numberDays);
echo $numberDays;
echo floor((strtotime('04-04-2017')-strtotime('14-03-2017'))/(60*60*24));
Run Code Online (Sandbox Code Playgroud)
使用新的DateTime扩展,PHP 5.3+:
$date1 = new DateTime("2010-07-06");
$date2 = new DateTime("2010-07-09");
// this calculates the diff between two dates, which is the number of nights
$numberOfNights= $date2->diff($date1)->format("%a");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4224 次 |
| 最近记录: |