如何在不借助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());
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...