C# How can I check if today is the first Monday of the month?

前端 未结 5 1092
太阳男子
太阳男子 2021-01-01 12:04

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 toda         


        
5条回答
  •  半阙折子戏
    2021-01-01 12:31

    You could do the following

    DateTime dt = ...;
    if (dt.DayOfWeek == DayOfWeek.Monday && dt.Day <= 7) {
      // First Monday of the month
    }
    

提交回复
热议问题