Skip to content

Instantly share code, notes, and snippets.

@hickford hickford/example.cs
Created Mar 8, 2012

Embed
What would you like to do?
Python's timedelta for .NET and C#
TimeDelta(hours:1,minutes:30)
public static class TimeSpanExtensions
{
// <summary>
// Returns a Timespan initialized to the specified number of weeks, days, hours, minutes, seconds, and milliseconds.
// </summary>
public static TimeSpan TimeDelta(int weeks=0, int days=0, int hours=0, int minutes=0, int seconds=0, int milliseconds=0)
{
return new TimeSpan(days:weeks*7+days,hours:hours,minutes:minutes,seconds:seconds,milliseconds:milliseconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.