Sign in to follow this  
Followers 0
soulhealer

is this the best way to transform ms timer into clock timer?

3 posts in this topic

#1 ·  Posted (edited)

hi, i wonder if there is a better way, because this takes a lot of memory and CPU:

$timeinMs = 358735672;ms, for example.

$hour = Floor($timeinMs / 3600);this define the hours
$minute = Floor(($timeinMs - ($hour * 3600)) / 60);this define the minutes
$second = $timeinMs - ( $hour * 3600 ) - ( $minute * 60 );this define the seconds

it takes a lot of memory to refresh the transformation in every seconds, which means, it counts that way every seconds. is there a better & shorter way? thanks.

Edited by soulhealer

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't think the above code is the cause of your high CPU usage.

Even on my pretty old PC, it runs in ~0.1 ms. Which means there are unused 999.9 ms in every second for something else.

Which means that either you're repeating the above code way more often than you should, or something else is the problem.

Btw, for these calculations to be correct, the total time ($timeinMs) should be in seconds, not milliseconds, of course. I suppose that's a typo?

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

I don't think the above code is the cause of your high CPU usage.

Even on my pretty old PC, it runs in ~0.1 ms. Which means there are unused 999.9 ms in every second for something else.

Which means that either you're repeating the above code way more often than you should, or something else is the problem.

Btw, for these calculations to be correct, the total time ($timeinMs) should be in seconds, not milliseconds, of course. I suppose that's a typo?

yeah, it should be in seconds, i mistyped it :D thanks anyway for noticing my thread.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0