var year,month,days:integer;read(year,month);
case month of
1,3,5,7,8,10,12:days:=31;
4,6,9,11:days:=30;
2: if (year mod 400=0) or( (year mod 4=0) and (year mod 100<>))
then days:=29 else days:=28;
end;
case month of
1,3,5,7,8,10,12:days:=31;
4,6,9,11:days:=30;
2: if (year mod 400=0) or( (year mod 4=0) and (year mod 100<>))
then days:=29 else days:=28;
end;
解决方案 »
- 如果在Delphi里我要控制两个Button按钮,那两个单源程序要分开写吗?
- 从excel中将数据导入到数据库
- 大家帮忙看下呀,我是新手,老是提示“不正常地定义参数对象。提供了不一致或不完整的信息。”在线等
- 如何将字符串CBR_115200转换成相应的cardinal值,正确的赋给DCB中的baudrate参数?
- Delphi连接Oracle的问题!请各位大虾赐教!!!!在线等!
- myling(阿德) 关于《NeHe的opengl框架delphi版》
- 菜鸟提问:Midas结构程序,访问提示“拒绝访问”
- Delphi DLL 中不能创建含ActiveX 的 Form,如何调用CoInitialize()
- dbgrid控件,在多行选择后,如何实现从每选中的行里读出某个字段的值,看里面代码;(急
- -----VCL-------
- 错误就是因为病在这里
- 一个相当简单的问题,菜鸟也可以进。
2: if (year mod 400=0) or( (year mod 4=0) and (year mod 100<> 0 ))
----
1,3,5,7,8,10,12:days=31;
2: if(year mod 400=0 and not (year mod 100=0) and (year mod 4=0)
then days:29;
else
days:28;
4,6,9,10:days:=30;
else showmessage('输入的月份是无效的!");
end;
Yr, Mnth, Day: Word;
begin
DecodeDate(Date, Yr, Mnth, Day);
cae mnth of
1,3,5,7,8,10,12:day=31;
2: if IsLeapYear(Yr) then day:=29;
else day:=28;
4,6,9,11:day:=30;
end;
end;
俺设定的日期为string型,格式为'yyyy-mm-dd'
这段代码就是判断用户输入的日期是否是合法日期
function CheckDateString(DateString:string):bool;
var year,month,day,maxday:integer;
begin
result:=true;
//长度检查
if length(DateString)<>10 then
begin
result:=false;
exit;
end;
//格式合法性
if (DateString[5]<>'-') or (DateString[8]<>'-') then
begin
result:=false;
exit;
end;
//年合法性
try
year:=strtoint(copy(DateString,1,4));
except
result:=false;
exit;
end;
if year<1 then
begin
result:=false;
exit;
end;
//月合法性
try
month:=strtoint(copy(DateString,6,2));
except
result:=false;
exit;
end;
if (month<1) or (month>12)then
begin
result:=false;
exit;
end;
//日合法性
try
day:=strtoint(copy(DateString,9,2));
except
result:=false;
exit;
end;
case month of
1: maxday:=31;
2: begin
if (year mod 4)=0 then maxday:=29 else maxday:=28;
end;
3: maxday:=31;
4: maxday:=30;
5: maxday:=31;
6: maxday:=30;
7: maxday:=31;
8: maxday:=31;
9: maxday:=30;
10: maxday:=31;
11: maxday:=30;
12: maxday:=31;
end;
if day>maxday then
begin
result:=false;
exit;
end;
end;
恺撒大帝引进的算法改进的。它采用的是闰年制也就是现行的制度,不过有一个需要注意的
地方就是,这个历法并不是连续的,中间缺少了11天。1752年9月2日之后的那一天并不是
1752年9月3日,而是1752年9月14日。也就是说,从1752年9月3日到1752年9月13日的11天
并不存在。抹掉这11天是由英国议会做出的决定。所以要计算某年每个月的天数的话,除了
要考虑是否是闰年以外,还要考虑1752年的9月。
程序可以这样:
if year=1752 then
case month of
1,3,5,7,8,10,12:days:=31;
2:days:=29;
9:days:=19;
4,6,11:days:=30;
end
else
case month of
1,3,5,7,8,10,12:days:=31;
4,6,9,11:days:=30;
2:if (year mod 400=0) or( (year mod 4=0) and (year mod 100<>))
then days:=29 else days:=28;
end;
恺撒大帝引进的算法改进的。它采用的是闰年制也就是现行的制度,不过有一个需要注意的
地方就是,这个历法并不是连续的,中间缺少了11天。1752年9月2日之后的那一天并不是
1752年9月3日,而是1752年9月14日。也就是说,从1752年9月3日到1752年9月13日的11天
并不存在。抹掉这11天是由英国议会做出的决定。所以要计算某年每个月的天数的话,除了
要考虑是否是闰年以外,还要考虑1752年的9月。
程序可以这样:
if year=1752 then
case month of
1,3,5,7,8,10,12:days:=31;
2:days:=29;
9:days:=19;
4,6,11:days:=30;
end
else
case month of
1,3,5,7,8,10,12:days:=31;
4,6,9,11:days:=30;
2:if (year mod 400=0) or( (year mod 4=0) and (year mod 100<>))
then days:=29 else days:=28;
end;