C#中如何检查,如果今天是本月的第一个星期一? [英] C# How can I check if today is the first Monday of the month?
本文介绍了C#中如何检查,如果今天是本月的第一个星期一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查如果今天是这个月的第一个星期一?
下面的代码给了我这个月的最后一天,我应该怎么修改呢?
今天的DateTime = DateTime.Today;
的DateTime endOfMonth =新日期时间(
today.Year,
today.Month,
DateTime.DaysInMonth(today.Year,today.Month)
);
解决方案
如何:
今天的DateTime = DateTime.Today;
如果(today.DayOfWeek == DayOfWeek.Monday&放大器;&安培; today.Day< = 7)
的查找的每月的第一个星期一是稍微棘手。目前尚不清楚是否不需要那个 - 让我们知道,如果你需要的
请注意使用 DateTime.Today $ C的$ C>的一次的 - 这样你不与在被评估的条件的两部分之间的日期改变潜在的怪事结束
How can I check if today is the first Monday of the month?
The code below gives me the last day of the month, how should I modify this?
DateTime today = DateTime.Today;
DateTime endOfMonth = new DateTime(
today.Year,
today.Month,
DateTime.DaysInMonth(today.Year, today.Month)
);
解决方案
How about:
DateTime today = DateTime.Today;
if (today.DayOfWeek == DayOfWeek.Monday && today.Day <= 7)
Finding the first Monday of the month is slightly trickier. It's not clear whether or not you need that - let us know if you need that.
Note the use of DateTime.Today
once - that way you don't end up with potential oddities where the date changes between the two parts of the condition being evaluated.
这篇关于C#中如何检查,如果今天是本月的第一个星期一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文