SRL Archive - OSR Help

TimeRunning


Death12652

2010-12-18 20:34:50

So I have this


procedure Blah;
var
Amount : Integer;
begin
Amount := GetTimeRunning;
writeln(IntToStr(Amount));
end;

How can I change the miliseconds it outputs to hours minutes and seconds?

mormonman

2010-12-18 20:36:47

It's actually called TimeRunning. Just do writeln(TimeRunning); or writeln('Time Running: ' + TimeRunning);

3Garrett3

2010-12-18 20:38:41

From: mormonman
It's actually called TimeRunning. Just do writeln(TimeRunning); or writeln('Time Running: ' + TimeRunning);


This, just make sure you have srl included (as trivial as it may sound :p)

Feroc1ty

2010-12-18 20:52:46

And if you don't have the include you could make a function similar to this…

function fTimeFromStart():string;
var tempi:longint;
temps:string;
begin
tempi := GetSystemTime - scriptStart;
tempi := Floor(tempi / 1000);
temps := IntToStr(tempi mod 60);
if Length(temps) < 2 then
temps := '0' + temps;
tempi := Floor(tempi / 60);
temps := IntToStr(tempi mod 60) + ':' + temps;
if Length(temps) < 5 then
temps := '0' + temps;
tempi := Floor(tempi / 60);
temps := IntToStr(tempi mod 60) + ':' + temps;
if Length(temps) < 8 then
temps := '0' + temps;
result := temps;
end;

Bad Boy JH

2010-12-18 20:56:55

MSToTime, direct from Timing.scar
{*******************************************************************************
function MsToTime(MS, StrType: Integer): string;
By: ZephyrsFury, Nava2, and Rasta Magician
Description: 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
*******************************************************************************}
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;

Daniel

2010-12-24 03:17:17

Err, how about the in-built ConvertTime? :)

Death12652

2010-12-24 11:02:37

I used the TimeRunning function. It works great. If it stops working though I will use your suggestions.