DateUtils function DaysInAMonth(const AYear, AMonth: Word): Word;
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).
procedure TForm1.Button1Click(Sender: TObject); begin showmessage(inttostr(DaysInAMonth(2004,02))); end;
用乡长的方法最好,直接调用系统的;自已写的话参照下面函数: 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;
function DaysInAMonth(const AYear, AMonth: Word): Word;
begin
showmessage(inttostr(DaysInAMonth(2004,02)));
end;
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;
在USES中引用DateUtils提示后不到DateUtils.dcu
????
的办法可行,我认为是正确的,就用这个简单、明了