How do I format a string into days:minutes:hours:seconds?

I know that I need to use String.Format but there is very little explanation of its usage in the mono docs. So far I have..

 timeText = String.Format ("{0:00}:{0:00}:{1:00}:{0:00}",displayDays,displayHours, displayMinutes, displaySeconds);

..which does nothing as I have no idea what the 1's and 0's represent. Can anyone shed some light on this?

I prefer using TimeSpan (namespace System) in c#. It’s short and simple:

TimeSpan timeSpan = TimeSpan.FromSeconds(time);
string timeText = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

Well I figured out that the first zero is the order of the string it should read

currentCaseTimeText = String.Format ("{0:00}:{1:00}:{2:00}:{3:00}",displayDays,displayHours, displayMinutes, displaySeconds); 

And that gives me 00:00:00:00 with the correct vars assigned to the correctly formatted areas.

Here's the bit of code I'm using to display floating point seconds as MM:SS.FF ...

string FormatSeconds(float elapsed)
    int d = (int)(elapsed * 100.0f);
    int minutes = d / (60 * 100);
    int seconds = (d % (60 * 100)) / 100;
    int hundredths = d % 100;
    return String.Format("{0:00}:{1:00}.{2:00}", minutes, seconds, hundredths);

(EDIT) Recently realized I can simply use System.DateTime, as demonstrated in this javascript fragment:

var date : System.DateTime;
date = new System.DateTime(seconds * System.TimeSpan.TicksPerSecond);

If you want it as a nicely formatted string, use date.ToString(). This can also take a format parameter to control the formatting details, see MSDN docs for more info.

System.DateTime.Now.ToString(“yyyy/MM/dd hh:mm:ss”);

If you have a DateTime you can use custom format strings as explained here ...

Had the same problem made a video that simplifies it and gives you a link to string codes so the time can be displayed anyway you want. How to format time in unity (Unity Tutorial) - YouTube