根据年月可以推出每月的日期数,这个算法怎么写啊?

解决方案 »

  1.   

    ZT
    //DEMO: GetMonthDays(1996,2):=28function GetMonthDays(Y, M: Integer): integer;
    const
      sMonth: array[1..12] of Integer = (31, 28, 31, 30, 31, 30, 31,
        31, 30, 31, 30, 31);
    begin
      Result := 0;
      if (M < 1) or (M > 12) then Exit;
      Result := sMonth[M];
      if (M = 2) and IsLeapTrue(Y) then
        Inc(Result)
    end;
      

  2.   

    ZT
    //DEMO: if IsLeapTrue(1996)=True then ..function IsLeapTrue(Y: integer): boolean;
    begin
      Result := ((Y mod 4 = 0) and ((Y mod 100 <> 0) or (Y mod 400 = 0)))
        or (((Y mod 4) = 0) and ((Y mod 100) = 0) and ((Y mod 400) = 0));
    end;
      

  3.   

    用DayOfTheMonthUnitDateUtilsCategorydate/time routinesfunction DayOfTheMonth(const AValue: TDateTime): Word;DescriptionCall DayOfTheMonth to obtain the day of the month represented by a specified TDateTime value. DayOfTheMonth returns a value between 1 and 31.
      

  4.   

    根据年月可以推出每月的日期数:
    不需要甚末算法,有daysof()函数。//记得不是很清楚,可能是dayof daysin ...,自己看一下delphi的帮助。例:
    2003年8月temp_data:='2003-08-'+'1';  //当月第一天
    MonthDays=daysof(strtodate(temp_data)); //当月的天数
      

  5.   

    function DayCount( theDay : TDateTime) : Integer;
    //Return the count of days in a month
    //Copy Right 549@11:48 2003-8-7
    begin
      Result := DayOf( EndOfTheMonth( theDay ) );
    end;
      

  6.   

    借楼主宝地一用
    鉴别CSDN星星的含金量http://expert.csdn.net/Expert/topic/2147/2147062.xml?temp=.9299433