如何解决如何在不借助TimeToStrconst datetime:TDateTime; const formatsettings:TFormatSettings的情况下从TTime中删除秒数
| 如何从TTime变量中删除秒,而又不使用使用TimeToStr(const datetime:TDateTime; const formatsettings:TFormatSettings)来获得没有秒的TTime值的额外开销? 即这就是我需要的-> HH:MM:00。 是否可以执行某种数学运算(例如将值与或进行或运算)?解决方法
var
t: TTime;
iHour,iMin,iSec,iMSec: Word;
DecodeTime(t,iHour,iMSec);
t := EncodeTime(iHour,0);
, uses
...,DateUtils;
var
t: TTime;
begin
t := ...;
t := RecodeSecond(t,0);
end;
, var
t : TTime;
t := Trunc(t * MinsPerDay) / MinsPerDay;
编辑:
这是截断秒数的更准确的功能。
在舍入之前,它会将时间舍入到最接近的毫秒。
uses
SysUtils;
const
FMSecsPerDay: Double = MSecsPerDay;
FMSecsPerMinute: Double = SecsPerMin * MSecsPerSec;
FMinsPerDay: Double = HoursPerDay * MinsPerHour;
function TruncateSeconds(aTime: TDateTime): TDateTime;
begin
{ - Round to closest millisecond before truncating the seconds }
Result := Trunc(Round(aTime * FMSecsPerDay) / FMSecsPerMinute) / FMinsPerDay;
// -- Time in Milliseconds --
// ------------- Time in minutes -----------------------
end;
, LongTimeFormat=\"hh:mm\";
Label1->Caption=TimeToStr(Time());
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。