How to Format a Time String with C# in Unity 3D

You are here

(This is only here for personal reference, since this is rather basic programming …)

///

/// Formats the input string (in seconds) as a human readable /// string in the form of MM:SS. /// /// /// A of the current playing time. /// private string formatedTimeString (string input) { int seconds; int minutes;

minutes = Mathf.FloorToInt(input / 60);
seconds = Mathf.FloorToInt(input - minutes * 60);
string r = (minutes < 10) ? "0" + minutes.ToString() : minutes.ToString();
r += ":";
r += (seconds < 10) ? "0" + seconds.ToString() : seconds.ToString();
return r;

}

/