Skip to main content

Converts the number of seconds to a string displaying hours and minutes.

/// <summary>
/// Converts the seconds to an hour \ min display string.
/// </summary>
/// <example>
///     int seconds = 7863;
///     string display = seconds.SecondsToString(); // 2 hours 11 mins
/// </example>
/// <param name="totalSeconds">The \total seconds.</param>
/// <returns>A string in the format x hours y mins.</returns>
public static string SecondsToString(this int totalSeconds)
{
    var s = TimeSpan.FromSeconds(totalSeconds);
    return string.Format("{0} hours {1} mins", (int)s.TotalHours, s.Minutes);
}