时间计数器

291646229468847.png

{ 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;


291646287271114.png
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;




转载于:https://www.cnblogs.com/xe2011/p/3875874.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值