Double - FromMilliseconds
Returns a TimeSpan that represents a specified number of milliseconds, where the specification is accurate to the nearest millisecond.
public static void Main() { double[] values = { 1, 24, 3600, 123456789.8, 1234567898765.4, 10000000, 600000000000, 889944220000 }; Console.WriteLine("{0,21}{1,18}","FromMilliseconds", "TimeSpan"); Console.WriteLine("{0,21}{1,18}","--------", "--------"); foreach (double value in values) { // C# Extension Method: Double - FromMilliseconds TimeSpan interval = value.FromMilliseconds(); string timeInterval = interval.ToString(); int pIndex = timeInterval.IndexOf(':'); pIndex = timeInterval.IndexOf('.', pIndex); if (pIndex < 0) timeInterval += " "; Console.WriteLine("{0,21}{1,26}", value, timeInterval); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Returns a that represents a specified number of milliseconds. /// </summary> /// <param name="value">A number of milliseconds.</param> /// <returns>An object that represents .</returns> public static TimeSpan FromMilliseconds(this Double value) { return TimeSpan.FromMilliseconds(value); } }