用delphi将HH:MM:SS转换为秒或分钟 [英] convert HH:MM:SS to seconds or minutes with delphi

查看:218
本文介绍了用delphi将HH:MM:SS转换为秒或分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能建议我将格式为HH:MM:SS的持续时间仅转换为秒或分钟的最佳方法吗?

Can someone advise me on the best way to convert a duration formated HH:MM:SS to seconds or minutes only?

ie。 00:01:49 = 109secs

ie. 00:01:49 = 109secs

我在使用此代码但不起作用

I´m using this code but not work

var
i: real;
j: integer;
begin
i := frac(real(StrToTime('00:00:01')));
j := trunc(frac(real(StrToTime('01:00:00'))) / i );
memo2.lines.add(inttostr(j));

当我尝试使用00:10:00的代码返回599

when I try the code with 00:10:00 return 599

谢谢

推荐答案

用于处理工期的非常灵活的工具是 TTimeSpan 在System.TimeSpan单元中找到。您可以按不同单位(秒,分钟,小时,...)获得结果,并根据需要设置其格式。

A very flexibel tool for handling durations is TTimeSpan found in unit System.TimeSpan. You can get the result in different units (second, minutes, hours, ...) and format that to your needs.

var
  timeSpan: TTimeSpan;
begin
  timeSpan := TTimeSpan.Parse('00:01:49');
  memo2.lines.add(Format('%1.1f min', [timeSpan.TotalMinutes]));
end;

这篇关于用delphi将HH:MM:SS转换为秒或分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆