德尔福的日期和时间

Ale*_*lex 0 delphi datetime

嘿,如果我想要更新自己的日期和时间,我该怎么写?Label3.Caption:= TimeToStr(时间)这只是向我显示时间,当我打开程序时,但我想要一个时间,每秒更新一次表格( - >像普通时钟那样).

小智 11

1)在表单上删除TTimer对象

2)将其"Interval"属性设置为1000,将其"Enabled"属性设置为true.

3)双击它以创建OnTimer事件处理程序.修改它看起来像这样:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    Label3.Caption := TimeToStr(Time)
end;
Run Code Online (Sandbox Code Playgroud)

你有它......


stu*_*lly 6

您可以使用Timer组件每秒更新标签标题.

  1. 在表单上放一个计时器.
  2. Interval属性设置为500,这将每半秒更新一次标题.
  3. 将Enabled属性设置为true.
  4. 双击计时器并添加以下代码.

    Label3.Caption:= TimeToStr(时间)

您还可以使用FormatDateTime函数更改时间显示方式