C 如何验证输入日期是否在日期间隔内?
我正在使用c语言,我们现在的课程是关于结构的。这是我代码的一部分,“temp”是一个结构,里面也有一个日期结构。但是,在某些情况下,某些有效日期直到最后一个条件才能生效C 如何验证输入日期是否在日期间隔内?,c,date,dateinterval,C,Date,Dateinterval,我正在使用c语言,我们现在的课程是关于结构的。这是我代码的一部分,“temp”是一个结构,里面也有一个日期结构。但是,在某些情况下,某些有效日期直到最后一个条件才能生效 if( temp.Date.year >= start.year && temp.Date.year <= end.year) if( (temp.Date.year >= start.year && temp.Date.year <= end.year) &a
if( temp.Date.year >= start.year && temp.Date.year <= end.year)
if( (temp.Date.year >= start.year && temp.Date.year <= end.year) && (temp.Date.month >= start.month && temp.Date.month <= end.month) )
if( (temp.Date.year >= start.year && temp.Date.year <= end.year) && (temp.Date.month >= start.month && temp.Date.month <= end.month) && temp.Date.day >= start.day && temp.Date.day <= end.day)
isDateValid = 1;
如果(temp.Date.year>=start.year&&temp.Date.year=start.year&&temp.Date.year=start.month&&temp.Date.month=start.year&&temp.Date.month=start.day&&temp>使用KISS方法。保持小而简单
你可以使用一系列奇怪的条件,或者干脆把约会转换成更方便的方式
unsigned long start = start.Date.Year * 10000ul + start.Date.month * 100 + start.Date.day;
对temp和end执行相同的操作
这将为我们提供一些易于比较的数值YYYYMMDD
if (start <= temp && temp <= end)
isValid = true;
if(开始)请了解有关格式、缩进和制作缩进的信息。“在某些情况下,某些有效日期直到最后一个条件才能进入”-->发布这些案例比只说存在一些案例更能提供信息。发布问题案例的值会增加问题的价值。无符号长
与简单使用无符号长
相比,在这里没有什么好处,除非RHS也使用无符号长
数学。建议开始日期.Year*10000
-->start.Date.Year*10000ul
。