Format String Minutes:Seconds

Hi I’m making a timer that counts down a variable. I’m trying to format the string in my GUI. The variable is time in seconds.

Is it possible to keep this one variable or do I need to split the variables into minutes and seconds? And what’s the line for formatting time?

Try this for size:

var someString = String.Format("{0:0}:{1:00}", Mathf.Floor(yourTime/60), yourTime % 60);

This is just a elaborate version of @mike’s solution

#pragma strict

var time:int=0;
function Start () {


function Update () {

function countDown()

function  OnGUI(){
	var minute:int =  (int) Mathf.Abs(time/60);

	var seconds:int =time%60;
	var labelString: String=minute.ToString("00")+":"+seconds.ToString("00");

Made my own version to display a “time elapsed” counter in Unity 5 and display it in a canvas:

DateTime startTime;
TimeSpan elapsedTime;
void Start () {
	startTime = DateTime.Now;
void LateUpdate () {
	elapsedTime = DateTime.Now - startTime;
	string displayTime = String.Format("{0:00}:{1:00}:{2:000}", 
GetComponent<Text>().text = displayTime;

Dont forget to add “using System;” to be able to use DateTime.