DELPHI---返回某月有多少天,是星期几

今天有要求想返回一个月有多少天,在网上找了找,用以下的函数可以实现.

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1function DaysInAMonth(const AYear,AMonth:Word):Word;   //for   Delphi5
 2 begin
 3      Result:=MonthDays[(AMonth=2and IsLeapYear(AYear),AMonth];
 4 end;
 5
 6procedure TForm1.Button1Click(Sender: TObject);
 7var
 8 ss:Word;
 9 yy,mm,dd:Word;
10begin
11  DecodeDate(Now,yy,mm,dd);
12  ss:=DaysInAMonth(yy,mm);
13  ShowMessage(IntToStr(ss));
14
15end;

 

 比较可以学习和借鉴的地方是MonthDays 和IsLeapYear函数的实现:

ContractedBlock.gif ExpandedBlockStart.gif MonthDays
1{ The MonthDays array can be used to quickly find the number of
2  days in a month:  MonthDays[IsLeapYear(Y), M]      }
3
4const
5  MonthDays: array [Boolean] of TDayTable =
6    ((312831303130313130313031),
7     (312931303130313130313031));

 

 判断是否为润年:

ContractedBlock.gif ExpandedBlockStart.gif IsLeapYear
1function IsLeapYear(Year: Word): Boolean;
2begin
3  Result := (Year mod 4 = 0and ((Year mod 100 <> 0or (Year mod 400 = 0));
4end;

闰年的计算方法:公元纪年的年数可以被四整除,即为闰年;被100整除而不能被400整除为平年;

被100整除也可被400整除的为闰年。如2000年是闰年,而1900年不是。

判断是星期几:

ContractedBlock.gif ExpandedBlockStart.gif DayOfWeek
1function DayOfWeek(const DateTime: TDateTime): Word;
2begin
3  Result := DateTimeToTimeStamp(DateTime).Date mod 7 + 1;
4end;

 

 

ContractedBlock.gif ExpandedBlockStart.gif TimeStamp
1{ Date and time record }
2
3  TTimeStamp = record
4    Time: Integer;      { Number of milliseconds since midnight }
5    Date: Integer;      { One plus number of days since 1/1/0001 }
6  end;

转载于:https://www.cnblogs.com/moon25/archive/2008/08/20/1271900.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值