Convert seconds to HH:MM:SS with String.Format

Viewed 9114

I have a float that is an amount of seconds, I want to make a string in the format hh:mm:ss that represent a countdown from 24hours. I'm trying to use this code:

TimeToMissionsReady = 86400f - FromMissionCompletedSeconds;
TimeToMissionsReadyString = string.Format ("{0:00}:{1:00}:{2:00}", TimeToMissionsReady / 3600f, (TimeToMissionsReady / 60f) % 60f, TimeToMissionsReady % 60f);

Debug.Log (TimeToMissionsReadyString);

but it isn't working 'cause it shows weird stuff like: 24:60:30 and after a second 24:59:29

Am I doing something wrong?

2 Answers
Related