枚举某一时间段的有多少正点

来源:互联网 发布:淘宝的全民晒单怎么晒 编辑:程序博客网 时间:2024/05/02 23:18
var
myDay:integer;
leepDay:integer;
StaDateTime,EndDateTime:TDateTime;
Year1,Month1,Day1,Hour1,Minute1,
Second1,MilliSecond1:Word;
Year2,Month2,Day2,Hour2,Minute2,
Second2,MilliSecond2:Word;
i,j:integer;
s1,s2:string;
d:double;
begin
StaDateTime:=StrToDateTime('2005-12-10 0:00:00');
EndDateTime:=StrToDateTime('2005-12-10 12:00:00');
DecodeDateTime(StaDateTime,Year1,Month1,Day1,Hour1,Minute1,Second1,MilliSecond1);
DecodeDateTime(EndDateTime,Year2,Month2,Day2,Hour2,Minute2,Second2,MilliSecond2);
if EndDateTime-StaDateTime<=0 then d:=0 else
d:=EndDateTime-StaDateTime;
s1:=FloatToStr(d);
s1:=Copy(S1,1,Pos('.',s1)-1);
i:=StrToInt(s1);
i:=i*24;
if Hour2-Hour1>0 then i:=i+Hour2-Hour1 else
i:=i+24+Hour2-Hour1;
i:=i+1;
if i>744 then i:=0;
for j:=1 to i-1 do
  begin
    if Hour1<23 then
    Hour1:=Hour1+1
    else
    begin
       if Year1 mod 4=0 then leepDay:=29 else leepDay:=28;
      //判断月份的天数。
      case Month1 of
      1: myDay:=31;
      2: myDay:=leepDay;
      3: myDay:=31;
      4: myDay:=30;
      5: myDay:=31;
      6: myDay:=30;
      7: myDay:=31;
      8: myDay:=31;
      9: myDay:=30;
      10: myDay:=31;
      11: myDay:=30;
      12: myDay:=31;
      end;
      if Hour1+1=24 then
      begin
        if Day1<myDay then
        begin
          if Month1<12 then
          begin
            Day1:=Day1+1;
          end else
          begin
            Year1:=Year1+1;
            Month1:=1;
          end;
        end else
        begin
          if Month1<12 then
          begin
            Month1:=Month1+1;
          end else
          begin
            Year1:=Year1+1;
            Month1:=1;
          end;
          Day1:=1;
        end;
        Hour1:=0;
      end;
    end;
    S2:=IntToStr(Year1)+'-'+IntToStr(Month1)+'-'+IntToStr(Day1)+' '+IntToStr(Hour1)+':00:00';
    ShowMessage(s2);
    end;
  end;
 
原创粉丝点击