How to get the name of each day in next month?

后端 未结 5 513
无人共我
无人共我 2021-01-23 01:35
DateTime dt = new DateTime();
dt = DateTime.Now.AddMonths(1);
int x = DateTime.DaysInMonth(dt.Year, dt.Month);
MessageBox.Show(x.ToString());  // works ok - 31
         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-23 01:57

    This should do the job.

    DateTime Base = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1);
    int x = DateTime.DaysInMonth(Base.Year, Base.Month);
    while (Base.Day != x)
    {
        Console.WriteLine(Base.DayOfWeek.ToString());
        Base = Base.AddDays(1);
    }
    

提交回复
热议问题