Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a simple way to display minutes, seconds and milli seconds for timing the elapsed time in a game. Do I have to do the calculation myself with gameTime and display a variable for each part like a variable for minutes, secounds and milli seconds? Preciates some help! Thanks!

share|improve this question
Yes I think that you can do that with TotalTimeElapsed (I think that is the name of the attribute). That value might have a subvalue that holds the entire time value (hh:mm:ss) or you can define 3 or 4 string variables and then pass values of hours, minutes and seconds like you said. – NDraskovic Jul 16 '12 at 6:54
up vote 5 down vote accepted

You can already get all these three from GameTime: gameTime.TotalGameTime offers Minutes, Seconds and Milliseconds for units to measure how long the game has been going for.

int milliseconds = gameTime.TotalGameTime.Milliseconds;
int seconds = gameTime.TotalGameTime.Seconds;

If you just want the time since the last update, use gameTime.ElapsedGameTime.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.