将int变量格式化为mm:ss

Ton*_*ony 5 delphi time string-formatting

谁能帮助我如何在delphi中将int变量格式化为一分钟:秒?

示例:myVar:= 19;

我的标签标题应显示00:19

任何想法的人?谢谢

小智 13

这将避免溢出到小时的秒值的任何错误.

var
  secs: integer;
  str: string;
begin
  secs := 236;
  // SecsPerDay comes from the SysUtils unit.
  str := FormatDateTime('nn:ss', secs / SecsPerDay));

  // If you need hours, too, just add "hh:" to the formatting string
  secs := 32236;
  str := FormatDateTime('hh:nn:ss', secs / SecsPerDay));
end;
Run Code Online (Sandbox Code Playgroud)


ain*_*ain 8

假设myVar包含秒数:

label1.Caption := Format('%.2d:%.2d', [myVar div 60, myVar mod 60]);
Run Code Online (Sandbox Code Playgroud)