检查时间范围内是否有a日

检查时间范围内是否有a日

问题描述:

如何检查两个时间戳之间是否存在2月29日?

How to check if there is a February 29th in between 2 timestamps?

$date_from = '2007-06-01';
$date_to = '2013-05-30';

我知道在这个范围内2月29日是2倍,但是如何检查呢?

I know in this range there's 2 times a feb-29, but how do I check for it?

我想计算之间的天数,但but日不计算在内.

I want to count the days in between, but leap days don't count.

这将循环显示年份,但是在您找到a年之后会更加容易,因为下一个one年将是4年,依此类推.

This will loop through the years, but it is even easier after you find a leap year because the next one will be 4 years after, etc.

$date_from = strtotime('2007-06-01');
$date_to = strtotime('2013-05-30');

for($year=$date_from; $year<=$date_to; $year=strtotime('next year', $year)) {
    echo date('Y', $year);
    echo date('L', $year) ? 'Leap year' : 'Not leap year';
}

但是我认为您可以检查'Y'年是否可以被4整除.

But I think you can just check if the year 'Y' is evenly divisible by 4.