Provides extension methods for converting numeric values to System.TimeSpan instances, enabling fluent and readable time duration creation (e.g., 5.Seconds(), 3.Hours(), 2.Weeks()).
public static class NumberToTimeSpanExtensionsInheritance System.Object → NumberToTimeSpanExtensions
These extensions make it easy to create TimeSpan values in a more natural, readable way: - Instead of TimeSpan.FromHours(3), you can write 3.Hours() - Instead of TimeSpan.FromMinutes(30), you can write 30.Minutes() - Supports all numeric types: byte, sbyte, short, ushort, int, uint, long, ulong, and double - Weeks are converted to days (1 week = 7 days)
Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this byte days);days System.Byte
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
((byte)2).Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this double days);days System.Double
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
2.Days() => TimeSpan representing 2 days
7.Days() => TimeSpan representing 1 week
1.5.Days() => TimeSpan representing 1 day and 12 hoursCreates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this int days);days System.Int32
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
2.Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this long days);days System.Int64
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
2L.Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this sbyte days);days System.SByte
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
((sbyte)2).Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this short days);days System.Int16
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
((short)2).Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this uint days);days System.UInt32
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
2U.Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this ulong days);days System.UInt64
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
2UL.Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of days.
public static System.TimeSpan Days(this ushort days);days System.UInt16
The number of days.
System.TimeSpan
A System.TimeSpan representing days days.
((ushort)2).Days() => TimeSpan.FromDays(2)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this byte hours);hours System.Byte
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
((byte)3).Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this double hours);hours System.Double
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
3.Hours() => TimeSpan representing 3 hours
24.Hours() => TimeSpan representing 1 day
1.5.Hours() => TimeSpan representing 1 hour and 30 minutesCreates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this int hours);hours System.Int32
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
3.Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this long hours);hours System.Int64
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
3L.Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this sbyte hours);hours System.SByte
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
((sbyte)3).Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this short hours);hours System.Int16
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
((short)3).Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this uint hours);hours System.UInt32
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
3U.Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this ulong hours);hours System.UInt64
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
3UL.Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of hours.
public static System.TimeSpan Hours(this ushort hours);hours System.UInt16
The number of hours.
System.TimeSpan
A System.TimeSpan representing hours hours.
((ushort)3).Hours() => TimeSpan.FromHours(3)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this byte ms);ms System.Byte
The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
500.Milliseconds() => TimeSpan representing 500 milliseconds
1000.Milliseconds() => TimeSpan representing 1 secondCreates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this double ms);The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
500.0.Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this int ms);ms System.Int32
The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
500.Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this long ms);ms System.Int64
The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
500L.Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this sbyte ms);ms System.SByte
The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
((sbyte)500).Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this short ms);ms System.Int16
The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
((short)500).Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this uint ms);The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
500U.Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this ulong ms);The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
500UL.Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of milliseconds.
public static System.TimeSpan Milliseconds(this ushort ms);The number of milliseconds.
System.TimeSpan
A System.TimeSpan representing ms milliseconds.
((ushort)500).Milliseconds() => TimeSpan.FromMilliseconds(500)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this byte minutes);minutes System.Byte
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
((byte)30).Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this double minutes);minutes System.Double
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
30.Minutes() => TimeSpan representing 30 minutes
90.Minutes() => TimeSpan representing 1 hour and 30 minutesCreates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this int minutes);minutes System.Int32
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
30.Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this long minutes);minutes System.Int64
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
30L.Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this sbyte minutes);minutes System.SByte
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
((sbyte)30).Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this short minutes);minutes System.Int16
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
((short)30).Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this uint minutes);minutes System.UInt32
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
30U.Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this ulong minutes);minutes System.UInt64
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
30UL.Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of minutes.
public static System.TimeSpan Minutes(this ushort minutes);minutes System.UInt16
The number of minutes.
System.TimeSpan
A System.TimeSpan representing minutes minutes.
((ushort)30).Minutes() => TimeSpan.FromMinutes(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this byte seconds);seconds System.Byte
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
((byte)30).Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this double seconds);seconds System.Double
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
30.Seconds() => TimeSpan representing 30 seconds
90.Seconds() => TimeSpan representing 1 minute and 30 secondsCreates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this int seconds);seconds System.Int32
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
30.Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this long seconds);seconds System.Int64
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
30L.Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this sbyte seconds);seconds System.SByte
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
((sbyte)30).Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this short seconds);seconds System.Int16
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
((short)30).Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this uint seconds);seconds System.UInt32
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
30U.Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this ulong seconds);seconds System.UInt64
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
30UL.Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of seconds.
public static System.TimeSpan Seconds(this ushort seconds);seconds System.UInt16
The number of seconds.
System.TimeSpan
A System.TimeSpan representing seconds seconds.
((ushort)30).Seconds() => TimeSpan.FromSeconds(30)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this byte input);input System.Byte
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
((byte)2).Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this double input);input System.Double
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
2.Weeks() => TimeSpan representing 14 days
1.Weeks() => TimeSpan representing 7 days
0.5.Weeks() => TimeSpan representing 3.5 daysSince System.TimeSpan doesn't have a native concept of weeks, this method converts weeks to days (multiplying by 7).
Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this int input);input System.Int32
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
2.Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this long input);input System.Int64
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
2L.Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this sbyte input);input System.SByte
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
((sbyte)2).Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this short input);input System.Int16
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
((short)2).Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this uint input);input System.UInt32
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
2U.Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this ulong input);input System.UInt64
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
2UL.Weeks() => new TimeSpan(14, 0, 0, 0)Creates a System.TimeSpan representing the specified number of weeks.
public static System.TimeSpan Weeks(this ushort input);input System.UInt16
The number of weeks.
System.TimeSpan
A System.TimeSpan representing input weeks (converted to days: 1 week = 7 days).
((ushort)2).Weeks() => new TimeSpan(14, 0, 0, 0)