function DaysInMonth(const AValue: TDateTime): Word;
To chechy(chechy): 好象delphi中没有这个函数,我用的时候出错了: Undeclared identifier: 'dayofthemonth'
To chechy(chechy): 是不是还要声明什么?多多指教啊。
D6中,uses DateUtils; 我看错了,应该是 function DaysInAMonth(const AYear, AMonth: Word): Word; begin Result := MonthDays[(AMonth = 2) and IsLeapYear(AYear), AMonth]; end;
To chechy(chechy): 我用的是delphi5,uses DateUtils不行啊, 请问delphi5中uses ???.
D5还没有了。那么卧抄一下给你: const MonthDays: array [Boolean] of TDayTable = ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));function IsLeapYear(Year: Word): Boolean; begin Result := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)); end;function DaysInAMonth(const AYear, AMonth: Word): Word; begin Result := MonthDays[(AMonth = 2) and IsLeapYear(AYear), AMonth]; end;
chechy这么严谨的人也写了个别字,呵呵,有趣 收藏
chechy这么严谨的人也写了个大别字,呵呵,有趣 收藏
function DaysOfMonth(ADate: TDateTime): Word; var Year,Month,Day: Word; begin DecodeDate(ADate,Year,Month,Day); Result := MonthDays[IsLeapYear(Year),Month]; end; 哎呀!累死我了,请给分!
8仙过海,我来介绍另一种办法:
function DaysOfItsMonth(ADate: TDateTime): Word; var Y, M, D: Word; begin DecodeDate( ADate, Y, M, D ); ADate := EncodeDate( Y, M, 1 ); Result := Trunc( IncMonth(ADate, 1)-ADate ); end;
好象delphi中没有这个函数,我用的时候出错了:
Undeclared identifier: 'dayofthemonth'
是不是还要声明什么?多多指教啊。
我看错了,应该是
function DaysInAMonth(const AYear, AMonth: Word): Word;
begin
Result := MonthDays[(AMonth = 2) and IsLeapYear(AYear), AMonth];
end;
我用的是delphi5,uses DateUtils不行啊,
请问delphi5中uses ???.
const
MonthDays: array [Boolean] of TDayTable =
((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));function IsLeapYear(Year: Word): Boolean;
begin
Result := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0));
end;function DaysInAMonth(const AYear, AMonth: Word): Word;
begin
Result := MonthDays[(AMonth = 2) and IsLeapYear(AYear), AMonth];
end;
收藏
收藏
var
Year,Month,Day: Word;
begin
DecodeDate(ADate,Year,Month,Day);
Result := MonthDays[IsLeapYear(Year),Month];
end;
哎呀!累死我了,请给分!
function DaysOfItsMonth(ADate: TDateTime): Word;
var
Y, M, D: Word;
begin
DecodeDate( ADate, Y, M, D );
ADate := EncodeDate( Y, M, 1 );
Result := Trunc( IncMonth(ADate, 1)-ADate );
end;