Inno设置 - 如何格式化单词的时间跨度(秒,分钟,小时)

时间:2017-02-01 12:26:16

标签: inno-setup

我正在使用代码How to show percent done, elapsed time and estimated time progress?

我想用“秒”,“分钟”和“小时”代替数字,也就是代替“0:01:37”,我想显示:“1分37秒”。有可能吗?

2 个答案:

答案 0 :(得分:2)

只需将为Format提供的格式字符串更改为您想要显示的内容。

function TicksToStr(Value: DWORD): string;
var
  I: DWORD;
  Hours, Minutes, Seconds: Integer;
begin
  I := Value div 1000;
  Seconds := I mod 60;
  I := I div 60;
  Minutes := I mod 60;
  I := I div 60;
  Hours := I mod 24;
  Result := Format('%.2d hours, %.2d minutes, %.2d seconds', [Hours, Minutes, Seconds]);
end;

答案 1 :(得分:1)

更聪明的实现,跳过零并处理复数:

procedure AddTime(var S: string; Count: Integer; L: string);
begin
  if Count > 0 then
  begin
    if S <> '' then
    begin
      S := S + ' ';
    end;
    if Count > 1 then L := L + 's';
    S := S + Format('%d %s', [Count, L]);
  end;
end;

function TicksToStr(Value: DWORD): string;
var
  I: DWORD;
  Hours, Minutes, Seconds: Integer;
begin
  I := Value div 1000;
  Seconds := I mod 60;
  I := I div 60;
  Minutes := I mod 60;
  I := I div 60;
  Hours := I mod 24;

  AddTime(Result, Hours, 'hour');
  AddTime(Result, Minutes, 'minute');
  AddTime(Result, Seconds, 'second');
  if Result = '' then Result := '-'; { no time }
end;