HH:MM:SS game clock with modifiable start time error

I have implemented the following code. It used to work fine, but when I tried to add “startTime” the clock tries to display more than one seconds value at once. The startTime variable is set when the game is actually started (right now game begins but all players must tick in before it actually initialises everything). I would like to know what I’ve done wrong, and how to make it work perfectly, thanks!

Also, is there a reason why the timer GUI text is bold? When by default it is not?

    time = Mathf.FloorToInt(Time.time) - Mathf.FloorToInt(startTime);
    hours = time / 3600;
    minutes = (time % 3600) / 60;
    seconds = (time % 3600) % 60;
    prettyTime = string.Format("{0:00}:{1:00}:{2:00}", hours, minutes, seconds);
    GUI.Label(new Rect(10, 10, 250, 100), prettyTime);

70989-capture.jpg

As you can see the values are overlayed.

Did you try TimeSpan With DateTime?

time = Time.time - startTime;
System.TimeSpan calc = System.TimeSpan.FromSeconds(time);
System.DateTime actualCalc = System.DateTime.MinValue.Add(calc);
prettyTime = actualCalc.ToString(@"hh:mm:ss");
GUI.Label(new Rect(10, 10, 250, 100), prettyTime);

But without DateTime you can just do this.

prettyTime = string.Format("{0}:{1}:{2}",calc.Hours,calc.Minutes,calc.Seconds);