1

I have a chronometer used as a timer in a game. Currently it only shows seconds (by default). I have been trying to get the format to show in minutes:seconds:milliseconds. I tried but nothing is working. Here is the code I found on StackoverFlow that says it should work...but didn't. OR if you have any other solutions instead of chronometer please let me know! (This is in android, using java)

-Thanks

  Chronometer chronometer;

   chronometer.setFormat(MM:SS:mm);
newbdeveloper
  • 97
  • 2
  • 3
  • 12

1 Answers1

-1

Actually, there's a much nicer way of doing this:

void OnGUI() {
int minutes = Mathf.FloorToInt(timer / 60F);
int seconds = Mathf.FloorToInt(timer - minutes * 60);

string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
GUI.Label(new Rect(10,10,250,100), niceTime);
}

This will give you times in the 0:00 format. If you'd rather have 00:00, simply do

string niceTime = string.Format("{0:00}:{1:00}", minutes, seconds);

There's a couple of possibilities you have with the formats here: {0:#.00} would give you something like 3.00 or 10.12 or 123.45. For stuff like scores, you might want something like {0:00000} which would give you 00001 or 02523 or 20000 (or 2000000 if that's your score ;-) ). Basically, the formatting part allows any kind of formatting (so you can also use this to format date times and other complex types). Basically, this means {indexOfParameter:formatting}

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880