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

编程入门 行业动态 更新时间:2024-10-24 06:35:00
本文介绍了检查时间范围内是否有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.

更多推荐

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

本文发布于:2023-10-24 19:39:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!