Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
Python's timedelta for .NET and C#
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.