Hello can any one please tell me how can i display total time taken by a race car to complete a certain lap in HH:MM:SS:MSMS format in a GUI.
HH = Hours,
MM = Minutes,
SS = Seconds,
MSMS = Mini Seconds.
Thanks.
Shantanu.
Hello can any one please tell me how can i display total time taken by a race car to complete a certain lap in HH:MM:SS:MSMS format in a GUI.
HH = Hours,
MM = Minutes,
SS = Seconds,
MSMS = Mini Seconds.
Thanks.
Shantanu.
If you have the amount of seconds in a float (either from Time.timeSinceLevelLoad or Time.realtimeSinceStartup) you can calculate it yourself.
float theTimeInSec = Time.timeSinceLevelLoad;
//theTimeInSec = 1234.1345f; //<-- test with some
//value if you like.
//3600 seconds on a hour (60*60).
int HH = Mathf.FloorToInt(theTimeInSec / 3600.0f);
//remove all the elapsed hours
theTimeInSec %= 3600.0f;
//60 seconds on a minute.
int MM = Mathf.FloorToInt(theTimeInSec / 60.0f);
//remove all the elapsed minutes.
theTimeInSec %= 60.0f;
//1 second on a second ;oP.
int SS = Mathf.FloorToInt(theTimeInSec / 1.0f);
//remove the elapsed seconds.
theTimeInSec %= 1.0f;
//theTimeInSec is now a fraction of a second.
// since there are a 1000 ms on a second, multiply
// the fraction with 1000.
//use FloorToInt so it will not change untill it
// actually has changed (it would show 1 sec the
// first time after 0.5 sec if not used)
int MILLISECONDS = Mathf.FloorToInt(theTimeInSec * 1000.0f);
//just rememer that after 999ms it goes back to 0 so
// dont show more than 3 digits.
Debug.Log("HH " + HH.ToString("00") + " MM " + MM.ToString("00") + " SS " + SS.ToString("00") + ": MS" + MILLISECONDS.ToString("000"));
I presume you mean millisecond (ms) as I have no idea what mini seconds are.
//perlohmann
Thanks a lotperlohmann
yes its Milliseconds thanks for correcting me.
will keep that in mind next time.
![]()