在两个日期范围之间相交的天数 [英] Count of days intersecting between two date ranges

查看:65
本文介绍了在两个日期范围之间相交的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人会对如何最佳地计算两个日期范围之间相交的天数有任何想法吗?

Would anyone have any ideas of how to best calculate the amount of days that intersect between two date ranges?

推荐答案

获取一个新范围,该范围由开头的较晚部分和结尾的较早部分定义,并确定自每个时期开始以来的天数新范围内的一天.

Obtain a new range, defined by the later of the beginnings and the earlier of the ends, and determine the number of days since the beginning of the epoch for each day in that new range.

差异是交叉路口的天数.仅接受正值.

The difference is the number of days in the intersection. Accept only positive values.

进行了编辑,以考虑范围而不是单个日期.

Edited to take into account ranges instead of individual dates.

这篇关于在两个日期范围之间相交的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆