Timer in milliseconds to MM:SS:MS

I have a timer that shows the finished time eg. 2min:54sec:22mil
My total time is in milliseconds which is 17426.94.
So I have another variable that I need added to milliseconds, so after that has been added, how can I convert that into MM:SS:MS so I can display that on screen and store the total milliseconds for a leaderboard?

Here you go http://forum.unity3d.com/threads/63450-Racing-Timer-(again)

function FormatTime (time)


 var intTime : int = time;
 var minutes : int = intTime / 60;
 var seconds : int = intTime % 60;
 var fraction : int = time * 1000;
 fraction = fraction % 1000;
 timeText = String.Format ("{0:00}:{1:00}:{2:000}", minutes, seconds,fraction);
 return timeText;


There is no reason to try to calculate it yourself. Use the TimeSpan struct. It even contains a static method that will accept miliseconds:

TimeSpan ts = TimeSpan.FromMilliseconds(yourMiliseconds);

Then piece together the format you want using its Minutes, Seconds and Miliseconds properties, (see TimeSpan Struct (System) | Microsoft Learn) or call its ToString method with whatever format you wish, see TimeSpan.ToString Method (System) | Microsoft Learn.

work from there

if(Time.time % 60 == 0){

minutes ++;
if(minutes %60 ==0){
  minutes = 0;
if(hour ==24){
 minutes =0;