我有 4 个日期 startDate
、endDate
、periodStartDate
、periodEndDate
如果 startDate
和 endDate
表示的时间段与 periodStartDate
和 表示的时间段重叠,我需要一个方法返回 true code>periodEndDate
.
这是 C# 3.5,所以不能使用元组。喜欢建议的链接
我的大脑似乎无法正常工作,请有人帮帮我。
谢谢!
最佳答案
if (startDate<periodStartDate)//start date is older
{
if (periodStartDate < endDate) //if end date is later than start of period
return true;
else return false; //
}
else //period start is older
{
if (periodEndDate < startDate) //period ended before startdate
return false;
else
return true;
}
只需注意你想要“<”的位置,以及“<=”的位置
编辑(更优雅的解决方案):
if (end1<start2) || (end2<start1) return false
else return true;
关于c# - 检查重叠日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5705275/