Laptime timer using TimeSpan - force milliseconds to 00 and not 000?

Hey guys,
I’m using TimeSpan for a laptime timer in my racing game, which works great…but there’s 1 little hiccup I can’t seem to figure out, and that’s for the Milliseconds section of the timer, which is always in this format: 000, and I want to force it to be: 00 instead.

Here’s my code below:

private GUIText laptime;

void LateUpdate ()
{	
    // "timer" is being calculated in EventManager like this:
    // timer = (Mathf.Round((Time.time - startTime) * 100.0f) / 100.0f);
    laptime.text = "Laptime : " + SetTimeSpan( EventManager.timer );
}
    	 	 	
public static string SetTimeSpan( float time )
{	
    // Create TimeSpan variable
    System.TimeSpan timeSpan = System.TimeSpan.FromSeconds( time );
    return string.Format( "{0:D2}:{1:D2}:{2:00}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds );

}

Is there a better way to create this type of timer? And how can I force it to always be in this format: 00:00:00 instead of 00:00:000?

Thanks for your time!
Stephane

So that’s a fair enough way to do it - though I would have used {0:00}:{1:00}{2:00} thought I guess D2 is working for you :slight_smile: You just want to divide the milliseconds by 10.