怎样得到某个月的最后一天?(50分)

  • 主题发起人 a_lei33_4
  • 开始时间
这样可以?没实过!
if mounth = 12 then mouth = 0;
theDate := StrToDateTime(inttostr(mounth+1) + '-1-1)) - 1;
 
建立一个循环,从这个月的第一天开始,
不断的加一天,直到这个日期的月份发生变化。
 
const
a : array [1..12 ] of integer =
(31,28,31,30,31,30,31,31,30,31,30,31,30);
begin
lastdayofThemonth = a[month] ;
end;

yun (门+王)年有些特殊,但可以通过函数判断,来处理,
delphi内部的一些时间函数就是这样写的

 
easy,例如要2000年2月的最后一天
则:theDate:=StrToDate('2000-3-1')-1;
其实很简单,只先计算出下一个月的第一天,然后减一天,就是你想要的哪一天。
 
cj的考虑全面
 
Victortim的方法可以,但要注意求12月的最后
一天,别忘了年也减1
 
to RJU:年加一吧?
 
Delphi的元件面板上的Sample页上有一个日历元件,看看它的源码吧.
 
自己写吧,

to cj;
mounth?? mouth? month?哈哈。
 
hehe,that is easy:

IncMonth(EncodeDate(Year,month,1),1)-1;

:)
 
Function GetMonthLastDay(WhichDay:TDate):TDate;
var
Year1,Month1,Day1,Year2,Month2:Word;
Begin
Result:=WhichDay;
DecodeDate(WhichDay,Year1,Month1,Day1);
Year2:=Year1;
Month2:=Month1+1;
if Month2=13 then
Begin
Month2:=1;
Year2:=Year2+1;
End;
Result:=EnCodeDate(Year2,Month2,1)-1;
End;
 
免費放送累試不償:

Function GetMonLast(Idate:TDate):TDate;
Var
Year,Month,Day:Word;
Begin
DecodeDate(IDate,Year,Month,Day);
If Month=12 Then
Begin
Year:=year + 1;
Month:=01
End Else Month:= Month + 1;
Result:=Encodedate(Year,Month,01) - 1;
End;
 
還要不要取每個月的1號的函數!!!
 
...Sorry,MMX
俺的思路还不算坏的过分啊,呵呵……
 
接受答案啦.
 
顶部