C gets three method summaries of the number of days in the current month

  • 2020-06-03 08:06:17
  • OfStack

Method 1: the one with the most content

int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInMonth(DateTime.Now.Year ,DateTime.Now.Month);

Method 2: // The strangest one

DateTime dtNow = DateTime.Today; int days = dtNow .AddDays(1 - dtNow .Day).AddMonths(1).AddDays(-1).Day;

Method 3: // The most common one

DateTime dtNow = DateTime.Now; int days = DateTime.DaysInMonth(dtNow.Year ,dtNow.Month);


Related articles: