两个日期之间的php天数列表 [英] php days between two dates list
本文介绍了两个日期之间的php天数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过查看代码,您知道问题出在哪里吗?
Do you know what the problem is by looking at the code?
如果您能帮助我,我会很高兴:
I would be happy if you helped me:
list($from_day,$from_month,$from_year) = explode(".","27.09.2012");
list($until_day,$until_month,$until_year) = explode(".","31.10.2012");
$iDateFrom = mktime(0,0,0,$from_month,$from_day,$from_year);
$iDateTo = mktime(0,0,0,$until_month,$until_day,$until_year);
while ($iDateFrom <= $iDateTo) {
print date('d.m.Y',$iDateFrom)."<br><br>";
$iDateFrom += 86400;
}
两次写相同问题的日期
10月(31日)写下2次历史记录的结果是10月30日结束:(
October (31) for writing 2 times in history draws the ends October 30th: (
2012年9月27日
27.09.2012
2012年9月28日
28.09.2012
...
2012年10月26日
26.10.2012
2012年10月27日
27.10.2012
[[[28.10.2012]]
[[[28.10.2012]]
2012年10月29日
29.10.2012
2012年10月30日
30.10.2012
推荐答案
- Your problem is because you have set time to 00:00:00, set it to 12:00:00. That is because the Daylight saving time.
- Stop using date() function, use Date and Time classes.
解决方案(PHP> = 5.4):
$p = new DatePeriod(
new DateTime('2012-09-27'),
new DateInterval('P1D'),
(new DateTime('2012-10-31'))->modify('+1 day')
);
foreach ($p as $d) {
echo $d->format('d.m.Y') . "\n";
}
解决方案(PHP< 5.4)
$end = new DateTime('2012-10-31');
$end->modify('+1 day');
$p = new DatePeriod(
new DateTime('2012-09-27'),
new DateInterval('P1D'),
$end
);
foreach ($p as $d) {
echo $d->format('d.m.Y') . "\n";
}
这篇关于两个日期之间的php天数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文