简体   繁体   中英

date and time in delphi

hey, what do i have to write, if i want date&time which updates itself? Label3.Caption := TimeToStr(Time) this just shows me the time, when i opened the program, but i want a time, that updates to the form every second (--> like a normal clock does).

1) Drop a TTimer object on your form

2) Set its 'Interval' propert to 1000 and its 'Enabled' property to true.

3) Double click on it to create an OnTimer event handler. Modify it som it looks something like this:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    Label3.Caption := TimeToStr(Time)
end;

And there you have it...

You can use the Timer component to update the label caption every second.

  1. Drop a timer on your form.
  2. Set the Interval property to 500, which will update the caption every half second.
  3. Set the Enabled property to true.
  4. Double click on the timer and add the following code.

    Label3.Caption := TimeToStr(Time)

You can also use the FormatDateTime function, to change how time is displayed

So drop a timer on the form, set to tick every 500ms or so, and write the time to your text time field in the event handler for the timer. You need to tick faster than smallest time interval you want to display. Note also that windows timers are pretty low priority, so if the CPU gets loaded, your timer might seem to "stick".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM