Thursday, August 5, 2010

Convert the value ( i.e. Duration in Seconds ) to HH:MM:SS

///
/// Convert the value ( i.e. Duration in Seconds ) to HH:MM:SS
/// Ex: 5430 seconds is equal to 01 hour 30 min 30 sec therefore
/// output is 01:30:30
///

///
///
private string ConvertDurationFormat(int intDurationInSec)
{
const int iUnitOfSec = 60;
int iSec = (intDurationInSec % iUnitOfSec);
int iRemainder = Convert.ToInt16(intDurationInSec / iUnitOfSec);
int iMin = (iRemainder % iUnitOfSec);
int iHour = Convert.ToInt16(iRemainder / iUnitOfSec);
return String.Format("{0:00}:{1:00}:{2:00}", iHour, iMin, iSec);
}

No comments:

Post a Comment