Mega Code Archive

 
Categories / Delphi / Examples
 

Round time to 5 seconds

Title: Round time to 5 seconds This example shows, how to round time to 5 seconds. For example, if current time is 10:12:43, then rounded time will be 10:12:45 or if current time is 10:12:57, then rounded time will be 10:12:55. For this, we should multiply our variable of DateTime type to 17280 (this is count of minutes per year), round it and divide it on 17280 (for getting variable of DateTime type again). procedure TForm1.Button1Click(Sender: TObject); begin Caption:=DateTimeToStr(Round(Now*17280)/17280); end;