gpt4 book ai didi

c# - 我如何在年份的变化中找到下个月和前几个月

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:41 25 4
gpt4 key购买 nike

我有两个文本框(开始日期、结束日期)。如果开始日期和结束日期值介于任何一个月的 21 号和下个月的 20 号之间,从 startDate 月份开始,我可以做任何其他事情。

例如,

startdate(25/jan/2017) and enddate(20/feb/2017) : 可以做任何逻辑

开始日期(25/jan/2017)和结束日期(21/feb/2017):无法执行逻辑

我为此使用了一些逻辑,

if ((startDate2.Day >= 21 && endDate2.Day >= 21 && emonth == smonth) 
|| (startDate2.Day >= 21 && endDate2.Day <= 20 && emonth == smonth + 1)
|| (startDate2.Day <= 20 && endDate2.Day <= 20 && emonth == smonth)
|| (startDate2.Day <= 20 && endDate2.Day >= 21 && emonth == smonth - 1))
{
}

但由于这个 ((startDate2.Day <= 20 && endDate2.Day >= 21 && emonth == smonth - 1)),它不适用于开始日期(12 月份)和结束日期(1 月份)任何人都可以用正确的逻辑帮助我吗?

最佳答案

可能是因为您希望结束月份正好比开始月份少一个月

emonth == smonth -1

这意味着如果您将十二月与一月进行比较,它就无法工作

1 == 12-1 => false

不提供任何完整的解决方案,但希望帮助您一点一点地理解;)

关于c# - 我如何在年份的变化中找到下个月和前几个月,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42161332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com