Link to home
Start Free TrialLog in
Avatar of SaLz
SaLz

asked on

GetTickCount in Clock Format - Day/Hours/Minutes/Seconds/Milliseconds

Hi, I need GetTickCount in a small and simple Clock Format - Day/Hours/Minutes/Seconds/Milliseconds - 00:00:00:00:000

so it will display the time from the milliseconds within the GetTickCount.

lets say this is the GetTickCount '189353435' this number should be in a clock format, if the GetTickCount was '10000' then it would read that in the correct way in the clock format 00:00:00:00:000 - Day/Hours/Minutes/Seconds/Milliseconds

Thanks

Sal.
Avatar of robert_marquardt
robert_marquardt

Where is the problem? GetTickCount returns Milliseconds.

    N := GetTickCount;
    Days := N div 24*60*60*1000;
    N := N mod 24*60*60*1000;
    Hours := N div 60*60*1000;
    N := N mod 60*60*1000;
    Minutes := N div 60*1000;
    N := N mod 60*1000;
    MilliSeconds := N div 1000;

Basic division and modulo.
Avatar of SaLz

ASKER

you don't get 500pts for half a job right, finish it off in a nice button format, where you just got to press it and it works.

am really sorry about this, but its been a very long day for me and am in one of them really lazy moods todays, I'd rather pay someone 500pts to do the maths than for me to do it for me at the present time, if you know what I mean. I normally do this stuff on my own, I know its basic, but I've got this killer hang over and I'm being lazy today, sorry you all.

so if you want to finish it off, it would be much appreciated. with a button and a label, just a copy and paste effort.

thanks

Sal.
SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
May I suggest an smaller effort (no math, only functions). Works on Delphi 7

function TickCountStr: string;
var
  TimeElapsed: TDateTime;
  Days: Integer;
  s: string;
begin
  TimeElapsed := IncMilliSecond(0, GetTickCount);
  Days := DaysBetween(0, TimeElapsed);
  result := Format('%.2d', [Days]) + FormatDateTime(':hh:nn:ss:zzzz', TimeElapsed);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(TickCountStr);
end;
You can get rid of this "s: string" : ) No harm, but no use for it there : )
Ooops, I have an error:
>    Hours := TickCount mod 60;
>    TickCount := TickCount div 60;
to be readed as:
    Hours := TickCount mod 24;
    TickCount := TickCount div 24;
Sorry....
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SaLz

ASKER

splendid work guys, esoftbg & Ivanov_G, you both deserve the points, you did the full work and each one has its own unique features.

esoftbg, the last post you did, increased your point share, I like that attention to detail and putting the code into a function, so it can be used over and over in just 1 line of code, plus the little things, the 2 00 to make up the full question of the clock format - day/hours/minutes/seconds/milliseconds - 00:00:00:00:000

I thankyou

Sal.
*crying* Mine wasn't even considered ... and it works too .. and it is smaller

Hehehehe, just kidding, the questioneer is who decide what is the answer
(But mine works too, test it SVP)
Avatar of SaLz

ASKER

I couldn't get your code to work on copy & paste, I'm sorry for that.

I should have posted saying it didn't work before accepting the other posts, but you didn't put 'DateUtils' in uses within your post for your code to work, I know it may be a little thing to judge on, but its just a little thing you could of added within your post, if you know what I mean, if you used 'DateUtils' you should add it into your post.

but since you made a comment about your code working and it does glide within the question, but you tripped up with the little things 'DateUtils', you got penalized for it, attention to detail is everything, it can make you or brake you.

your code is small and neat and does the job.

I will grant you 150pts, I will make another question for you to post and you can claim the points.

Sal.

given
esoftbg (first post) = 50pts
Ivanov_G = 200pts
knightmad = 150pts
esoftbg (second post) = 250pts