zoukankan      html  css  js  c++  java
  • 时间计数器


    { 1 h=1*60 m=1*60*60 s=1*60*60*1000 hs=3600000hs}
    function StartCount():string;
    {$j+}
    const
          h:Integer=0;
          m:Integer=0;
          s:integer=0;
    {$j-}
    begin
      inc(s);
      if s>=60 then
      begin
        Inc(m);
        s:=0;
      end;
      if m>=60 then
      begin
        Inc(h);
        m:=0;
      end;
      Result:=Format('%.2d:%.2d:%.2d',[h,m,s]);
    end;

    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    label1.Caption:= StartCount();
    end;
     
    ///倒计时
     
    function dec1():string;
    {$j+}
    const i:Integer=60*5;
    {$j-}
    begin
       Dec(i);
       Result:=Format('剩余时间:%d',[i]);
    end;

    procedure TForm1.Timer1Timer(Sender: TObject);{$j+}
    begin
         label1.Caption:=dec1;
    end;


    var
      h1: Integer = 0;
      m1: Integer = 0;
      s1: Integer = 0;

    procedure TForm2.Timer1Timer(Sender: TObject);
    begin
      if (h1 <= 0) and (m1 <= 0) and (s1 <= 0) then
        exit;

      Dec(s1);
      if s1 <= 0 then
      begin
        if (m1 > 0) or (h1 > 0) then
        begin
          Dec(m1);
          s1 := 60;
        end;
      end;
      if m1 < 0 then
      begin
        if h1 > 0 then
        begin
          Dec(h1);
          m1 := 60;
        end;
      end;

      Label1.Caption := Format('%.2d:%.2d:%.2d', [h1, m1, s1]);
    end;




  • 相关阅读:
    高程5.4 RegExp类型
    高程5.3 Date类型
    高程5.2.9归并方法
    20151119js上课总结
    从0~100之间随机取出不重复的10个数
    高程5.2.8迭代方法
    HTML常用标签
    20151118小问题
    20151117小问题
    《QT Creator快速入门》
  • 原文地址:https://www.cnblogs.com/xe2011/p/3875874.html
Copyright © 2011-2022 走看看