unit Unit37;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;
implementation
function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;
begin
if ((AYear<10000)and(AYear>0)and(AMonth>0)and(AMonth<13))then
begin
if((AMonth=1)or(AMonth=1)or(AMonth=1)or(AMonth=1)or(AMonth=1)or(AMonth=1)or(AMonth=1))then
begin
if((ADay>0)and(ADay<32))then
IsValidDate:=true
else
IsValidDate:=false;
end
else if((AMonth=4)or(AMonth=6)or(AMonth=9)or(AMonth=11))then
begin
if((ADay>0)and(ADay<31))then
IsValidDate:=true
else
IsValidDate:=false;
end
else if(AMonth=2)then
begin
if((AYear mod 400=0)and(ADay>0)and(ADay<30))or((AYear mod 400<>0)and(ADay>0)and(ADay<29))then
IsValidDate:=true
else
IsValidDate:=false;
end;
end
else
IsValidDate:=false;
end;
end.
该博客介绍了如何在 Delphi 中实现一个名为 IsValidDate 的函数,用于验证输入的年、月、日是否为一个有效的日期。函数考虑了不同月份的天数限制,包括闰年的处理。
613

被折叠的 条评论
为什么被折叠?



