djborec
2013-07-18 04:18:42
Is there any function which return current time in ms, not time computer running (GetSystemTime) ,but current time in ms.
2013-07-18 04:18:42
2013-07-18 04:39:19
function TimeRunning: string;
begin
Result := MsToTime(GetTimeRunning, Time_Formal);
end; 2013-07-18 04:44:01
(*
MsToTime
~~~~~~~~
.. code-block:: pascal
function MsToTime(MS, StrType: Integer): string;
Takes MS in milliseconds and outputs a string with hours, mins and
seconds. Different styles can be created with different StrType values:
Str Type:
- Time_Formal: 2 Hours, 47 Minutes and 28 Seconds
- Time_Short: 02h, 47m, 28s
- Time_Abbrev: 2 hr, 47 min, 28 sec
- Time_Bare: 02:47:28
- Time_FStop: 12.04.40
.. note::
by Zephyrsfury, Nava2 and Rasta Magician.
Example:
.. code-block:: pascal
*)
function MsToTime(MS, TheType: Integer): string;
var
STA: array [0..4] of TVariantArray;
Time: array [0..2] of Integer;
i: Integer;
begin
Result := '';
if (not(InRange(TheType, 0, High(STA)))) then
begin
srl_Warn('MsToTime', 'TheType: ''' + IntToStr(TheType) + ''' is not a valid value. Using Time_Bare.', warn_AllVersions);
TheType := Time_Bare;
end;
STA[Time_Formal] := [' Hours, ', ' Minutes and ', ' Seconds', False, 0];
STA[Time_Short] := ['h ', 'm ', 's', False, 2];
STA[Time_Abbrev] := [' hr ', ' min ', ' sec', False, 0];
STA[Time_Bare] := [':', ':', '', True, 2];
STA[Time_FStop] := ['.', '.', '', True, 2];
ConvertTime(MS, Time[0], Time[1], Time[2]);
for i := 0 to 2 do
if (Time[i] > 0) or (STA[TheType][3]) or (i = 2) then
Result := Result + PadZ(IntToStr(Time[i]), STA[TheType][4]) + STA[TheType][i];
end;2013-07-18 06:06:47
From: djborecHey djborec, is this possibly what you are after:
Is there any function which return current time in ms, not time computer running (GetSystemTime) ,but current time in ms.
function CurrentTimeToMS: Int64;
var
h, m, s, ms: Word;
begin
DecodeTime(Now, h, m, s, ms);
Result := ((Integer(h) * 3600000) + (Integer(m) * 60000) + (Integer(s) * 1000) + Integer(ms));
end;
function ConvertToMS(hours, minutes, seconds, milliseconds: Word): Int64;
begin
Result := ((Integer(hours) * 3600000) + (Integer(minutes) * 60000) + (Integer(seconds) * 1000) + Integer(milliseconds));
end;
var
h, m, s, ms: Word;
begin
ClearDebug;
WriteLn('CurrentTimeToMS: ' + IntToStr(CurrentTimeToMS));
DecodeTime(Now, h, m, s, ms);
WriteLn('DecodeTime(Now, h, m, s, ms) + ConvertTime(h, m, s, ms): ' + IntToStr(ConvertToMS(h, m, s, ms)));
end.2013-07-18 06:25:41
2013-07-18 06:42:51
From: masterBBNice Bart, that's definitely better way to do this!
Dudes… wtf…
writeln(86400000 * (Now - Floor(Now)));
e:
nvm, I am not sure what he is asking. But what I posted should be used instead of what janilabo posted.
function CurrentTimeToMS: Int64;
var
h, m, s, ms: Word;
begin
DecodeTime(Now, h, m, s, ms);
Result := ((Integer(h) * 3600000) + (Integer(m) * 60000) + (Integer(s) * 1000) + Integer(ms));
end;
function CurrentTimeToMSEx: Extended;
begin
Result := (86400000 * (Now - Floor(Now)));
end;
function ConvertToMS(hours, minutes, seconds, milliseconds: Word): Int64;
begin
Result := ((Int64(hours) * 3600000) + (Integer(minutes) * 60000) + (Integer(seconds) * 1000) + Integer(milliseconds));
end;
var
h, m, s, ms: Word;
begin
ClearDebug;
WriteLn('CurrentTimeToMS: ' + IntToStr(CurrentTimeToMS));
WriteLn('CurrentTimeToMSEx: ' + FloatToStr(CurrentTimeToMSEx));
DecodeTime(Now, h, m, s, ms);
WriteLn('DecodeTime(Now, h, m, s, ms) + ConvertTime(h, m, s, ms): ' + IntToStr(ConvertToMS(h, m, s, ms)));
end.
2013-07-18 07:04:23
logsAnHour := logs * 60 * 1000 / GetTimeRunning();writeln(86400000 * (Now - Floor(Now)));t := GetSystemTime;
repeat
wait(100);
until(TreeDown() or (GetSystemTime - t) > 3 * 60 * 1000);