delphi - 将 int 变量格式化为 mm :ss

标签 delphi time string-formatting

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

样本: myVar := 19;

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

有人知道吗?谢谢

最佳答案

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

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;

关于delphi - 将 int 变量格式化为 mm :ss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9175021/

相关文章:

arrays - 对数组进行排序并在Delphi中获取索引

持续时间的 HTML 时间标记

go - 如何在golang中实现随机 sleep

android - 如何获取应用所在的本地时间。正在运行,与设备时间无关?

python - 'string.format' 是否允许对可迭代对象/字典进行更多控制?

delphi - 如何让窗体像任务栏一样与屏幕边缘对齐?

delphi - 从 Delphi 2006 迁移到 Delphi XE2

delphi - 如果我不将函数的返回值保存在变量中,则函数的返回值存储在内存中的哪里?

.net - 使用相同的值填充多个 printf 格式占位符

python - 任何用于计数器的漂亮 python 字符串格式?