如题

解决方案 »

  1.   

    DateUtils
    function DaysInAMonth(const AYear, AMonth: Word): Word;
      

  2.   

    Returns the number of days in a specified month of a specified year.UnitDateUtilsCategorydate/time routinesfunction DaysInAMonth(const AYear, AMonth: Word): Word;DescriptionCall DaysInAMonth to obtain the number of days in the specified month of the specified year.AYear is a year between 1 and 9999 (inclusive).AMonth is a month between 1 and 12 (inclusive).
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      showmessage(inttostr(DaysInAMonth(2004,02)));
    end;
      

  4.   

    用乡长的方法最好,直接调用系统的;自已写的话参照下面函数:
    function TForm1.GetDaysOfMonth(aYear, aMonth: Integer): Integer;
      function IsLeapYear(aYear: Integer): Boolean;
      begin
        result := (aYear mod 4 = 0) and ((aYear mod 100 <> 0) or (aYear mod 400 = 0));
      end;const
      DaysInMonth: array[1..12] of Integer =
        (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    begin
      result := DaysInMonth[aMonth];
      if (aMonth = 2) and IsLeapYear(aYear) then Inc(result);
    end;
      

  5.   

    用一个大case来判断每个月,因为除了2月都是30或31天,其中2月还有判断是否是闰年
      

  6.   

    DaysInAMonth需引用什么
    在USES中引用DateUtils提示后不到DateUtils.dcu
    ????
      

  7.   

    weizi2000(秋风啊) 这位朋友的思路好清晰啊,呵呵像个女生
      

  8.   

    DaysInMonth就可以啊要加dateunits单元
      

  9.   

    我用的是D5,在USES中引用DateUtils提示找不到DateUtils.dcu
      

  10.   

    weizi2000(秋风啊) 
    的办法可行,我认为是正确的,就用这个简单、明了