3
A
回答
7
4
你应该使用FormatDateTime method这样的:
procedure TForm1.FormCreate(Sender: TObject);
const MyConst: Integer = 19;
begin
Caption:=FormatDateTime('nn:ss', EncodeTime(0, MyConst div 60, MyConst mod 60, 0));
end;
1
如果您确信您只想分钟和秒 - 一个快速的解决方案可能是格式('%d:%d',[(myVar div 60),(myVar mod 60)]);
相同的溶液已经提出了... :-)
+0
谢谢,除以更容易。生病做 – Tony 2012-02-07 11:19:18
10
这将避免任何错误行为溢出到小时秒值。
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;
+1
+1此解决方案很容易理解,并将与任何输入值一起使用。这也是最灵活的一个。 – 2012-02-07 15:56:11
0
扩大到布拉德的答案,我裹成检测,如果时间超过一个小时,并自动显示小时,如果这样的功能这一点。否则,如果不到一个小时,则不显示小时数。它还有一个可选参数,用于根据您的偏好定义是否在小时和分钟上显示前导零(即03:06:32
vs 3:6:32
)。这使得它更容易阅读。
function SecsToTimeStr(const Secs: Integer; const LeadingZero: Boolean = False): String;
begin
if Secs >= SecsPerHour then begin
if LeadingZero then
Result := FormatDateTime('hh:nn:ss', Secs/SecsPerDay)
else
Result := FormatDateTime('h:n:ss', Secs/SecsPerDay)
end else begin
if LeadingZero then
Result := FormatDateTime('nn:ss', Secs/SecsPerDay)
else
Result := FormatDateTime('n:ss', Secs/SecsPerDay)
end;
end;
不过,也有与显示时间,这是由你来决定许多不同的可能偏好。我不会在这里介绍所有可能的方法。
相关问题
- 1. PHP - 将多变量变量格式化为mysql DATETIME格式
- 2. 如何在int中将int格式化为价格格式?
- 3. Java - 将分钟和秒变为时间格式? (MM:SS)
- 4. 以hh格式化的时间:mm:ss
- 5. 格式化变量
- 6. 格式化日期。如何将int值格式化为日期格式?
- 7. MySQL的功能格式化时间在SQL查询为MM:SS
- 8. 格式化$ _GET变量的URL为Zend
- 9. DataGridView变量格式化
- 10. 格式化双变量
- 11. MySQL:如何将秒转换为mm:ss格式?
- 12. cakePHP:如何将持续时间格式设置为MM:SS
- 13. 将小于24的小数切换为[hh]:mm:ss格式?
- 14. 将[h]:mm:ss; @格式转换为Excel编号
- 15. 在交叉表中将数字转换为MM:SS格式
- 16. 将浮点数转换为时间格式mm:ss
- 17. 如何使用Python将格式化文件解析为变量?
- 18. 我们如何将JSON值格式化为PHP变量
- 19. 将[object HTMLElement]格式化为变量字符串
- 20. 将文本字符串格式化为双变量
- 21. 如何将JSON数据格式化为Objective-C变量?
- 22. 需要帮助将变量的输出格式化为列表
- 23. 如何将双变量格式化为两位小数?
- 24. C - 将输入字符串格式化为整型变量
- 25. 如何将字符串变量格式化为特定格式的日期?
- 26. 有没有更好的方法在Elixir中将秒数格式化为mm:ss格式?
- 27. 将C变量转换为JSON格式
- 28. MySql将“mm:ss”存储为“hh:mm”
- 29. 格式化与可变参数变量
- 30. 如何在Matplotlib中绘制时间(mm:ss)(格式化输出值)
没有提供真的,所有我需要的是将它与格式“MM:SS”这种格式 – Tony 2012-02-07 11:03:15