此函数返回两个日期之间的日期数组。检查两个日期之间的日期错误,无知
现在,它的工作完全正常,除了一些未知的原因,如果我把它的11月份或3月份作为参数,我得到的数组少一天。其他几个月工作完全正常。我绝对无能为力。
function getListofDatesInRange2($fromDate, $toDate)
{
$fromDate = str_replace("-","/", $fromDate);
$toDate = str_replace("-","/", $toDate);
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
$currentDateStr = date("m-d-Y",$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
}
return $dateMonthYearArr;
}
我重新编写了它,while循环解决了我的问题。 (虽然我不知道这个问题是摆在首位)
function getListofDatesInRange2($fromDate, $toDate)
{
$fromDate = str_replace("-","/", $fromDate);
$toDate = str_replace("-","/", $toDate);
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
array_push($dateMonthYearArr, date('m-d-Y', $fromDateTS));
while($fromDateTS < $toDateTS) {
$fromDateTS += 86400;
array_push($dateMonthYearArr, date('m-d-Y', $fromDateTS));
}
return $dateMonthYearArr;
}
可能重复的[如何找到两个指定日期之间的日期?](http://stackoverflow.com/questions/2736784/how-to-find-the-dates-between-two-specified-date) – Treffynnon 2012-04-19 21:44:00