ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

IntegerToTimeSpan

Converts an integer to a timespan

Source

/// <summary>
/// Converts the seconds to a timespan object.
/// </summary>
/// <param name="totalSeconds">The total seconds.</param>
/// <returns>A timespan object.</returns>
public static TimeSpan IntegerToTimeSpan(this int totalSeconds)
{
    return new TimeSpan(0, 0, totalSeconds);
}

Example

int seconds = 78654;

// Returns a TimeSpan object with 21 Hours, 50 Minutes and 54 Seconds
TimeSpan ts = seconds.IntegerToTimeSpan();

Author: K M Thomas

Submitted on: 25 mrt 2016

Language: C#

Type: System.Int32

Views: 3997