کد دلفی - تبدیل میلی ثانیه به روز و time

Convert Milliseconds to Days and Time
var startTick, endTick : Int64; begin startTick := GetTickCount; SomeLengthyFunction() ; endTick := GetTickCount; ShowMessage(MSecToTime(endTick - startTick)) ;

The Windows API function GetTickCount retrieves the number of milliseconds that have elapsed since Windows was started.
To get the number of milliseconds that passed while the SomeLengthyFunction was executing you need to subtract endTick value from the startTick value.

Here's a function that takes an amount of milliseconds, converts those milliseconds to days, hours, minutes and seconds and returns the string representation:

function MSecToTime(mSec: Int64): string; var dt : TDateTime; begin dt := mSec / MSecsPerSec / SecsPerDay; Result := Format('%d days, %s', ) ; end;

Note: The MSecsPerSec and SecsPerDay constants are defined in the SysUtils unit.

/ 0 نظر / 5 بازدید