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