如何让dateTimePicker1初始化为当月的最后一天?

解决方案 »

  1.   

    dateTimePicker1.Value = DateTime.Today.AddDays(1-DateTime.Today.Day).AddMonths(1).AddDays(-1);
      

  2.   

    int m=System.DateTime.DaysInMonth(System.DateTime.Now.Year,System.DateTime.Now.Month);
      

  3.   

    int m=System.DateTime.DaysInMonth(System.DateTime.Now.Year,System.DateTime.Now.Month);
    dateTimePicker1.Value =Convert.ToDateTime(System.DateTime.Now.Year+"-"+System.DateTime.Now.Month+"-"+m);
      

  4.   

    using System;
    int y = DateTime.Today.Year;
    int m = DateTime.Today.Month;
    int d = DateTime.DaysInMonth(y, m);
    dateTimePicker1.Value = new DateTime(y, m, d);
    这样当然可以,但一楼的方法更巧妙。
      

  5.   

    Date.DaysInMonth(Year(Now), Month(Now))