Is there any function which return current time in ms, not time computer running (GetSystemTime) ,but current time in ms.
Is there any function which return current time in ms, not time computer running (GetSystemTime) ,but current time in ms.
SRL has a function called TimeRunning built into it.
It works like this:
Simba Code:function TimeRunning: string;
begin
Result := MsToTime(GetTimeRunning, Time_Formal);
end;
I'm sure you could somehow edit or mod that to become pure MS
The function you're looking for is 'GetTimeRunning'. GetTimeRunning outputs in pure ms, which TimeRunning lacks as it utilises MsToTime:
Simba Code:(*
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;
Enjoy.
Ultimate Guide to Making a Superb Guide | Guide to the New Forum Layout | Guide to Simba's Features!
| Ranks and Cups | Info & Requirements!| Guide to Reputation! | Guide to Posting GOOD Bug ReportsCheck out the Ultimate Guide Directory! It contains every guide ever posted on the forums.
Hey djborec, is this possibly what you are after:
Added 2 ways to do it.Code: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.![]()
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.
Last edited by masterBB; 07-18-2013 at 10:33 AM.
Working on: Tithe Farmer
Nice Bart, that's definitely better way to do this!
So including Bart's method (which is A LOT more accurate):
Code: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.
Time
- GetTimeRunning
- Now
- GetSystemTime
GetTimeRunning
Returns the time since you pressed run in simba in ms. Is very useful for progress reports etc. Example usage:
Simba Code:logsAnHour := logs * 60 * 1000 / GetTimeRunning();
Now
Returns the current time and date. The number before the point represents the amount of days since 12/30/1899. Today it is 41473.
The second part returns the fraction of the day. For example, 6:00 -> 0.25 and 12:00 -> 0.5 and 18:00 -> 0.75. By multiplying it with the amount of ms in a day you can get the amount of ms passes since midnight.
Simba Code:writeln(86400000 * (Now - Floor(Now)));
GetSystemTime
GetSystemTime is the time the system is up and running in ms. It can be used for various tasks suchs as adding it as a failsafe to loops.
Simba Code:t := GetSystemTime;
repeat
wait(100);
until(TreeDown() or (GetSystemTime - t) > 3 * 60 * 1000);
Working on: Tithe Farmer
There are currently 1 users browsing this thread. (0 members and 1 guests)