Double - FromDays
Returns a TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.
public static void Main() { double[] values = { 0.000000006, 0.000123456, 1, 5.234567898, 12345.678987654, 0.000011574, 0.000694444, 0.041666666, 1, 20.84745602 }; Console.WriteLine("{0,21}{1,18}","FromDays", "TimeSpan"); Console.WriteLine("{0,21}{1,18}","--------", "--------"); foreach (double value in values) { // C# Extension Method: Double - FromDays TimeSpan interval = value.FromDays(); 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 days, where the specification is accurate to the nearest /// millisecond. /// </summary> /// <param name="value">A number of days, accurate to the nearest millisecond.</param> /// <returns>An object that represents .</returns> public static TimeSpan FromDays(this Double value) { return TimeSpan.FromDays(value); } }