19.01.2016, 22:49
Unless you visually update the race time during the race, don't rely on timers. Timers are roughly 20% off and this deviation will only increase the more iterations you do. They're completely unreliable when it comes to measuring any amount of time.
Use GetTickCount() and/or gettime() for the most accurate results. Save the timestamp at the beginning and get a new one whenever you need to show the time. Subtract them to find out the difference.
Using loops to convert time is also reinventing the wheel, because the modulo operator exists. This should do. Could probably be written a little shorter, but I just wrote this up of the top of my head.
Use GetTickCount() and/or gettime() for the most accurate results. Save the timestamp at the beginning and get a new one whenever you need to show the time. Subtract them to find out the difference.
Using loops to convert time is also reinventing the wheel, because the modulo operator exists. This should do. Could probably be written a little shorter, but I just wrote this up of the top of my head.
PHP код:
ms_to_time(input, &hours, &minutes, &seconds, &milliseconds)
{
milliseconds = input % 1000;
input -= milliseconds;
input /= 1000;
seconds = input % 60;
input -= seconds;
input /= 60;
minutes = input % 60;
input -= minutes;
input /= 60;
hours = input;
}