Sunday, August 10, 2008

Convert total seconds into hour, minute and second

Many time we need to convert total seconds to Hour, Minute,second format. Here is a simple implementation.

int totalSecondsInt, tempH, tempM, tempS;
decimal totalSecondsDec = Convert.ToDecimal(totalSecondsInt);
tempH = Convert.ToInt32(totalSecondsDec / 3600);
tempM = Convert.ToInt32(Math.Floor(((totalSecondsDec / 3600) - Convert.ToInt16((totalSecondsDec / 3600))) * 60));
tempS = Convert.ToInt32(Math.Floor(totalSecondsDec % 60));

No comments: