ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Elapsed

Get the elapsed time since the input DateTime

Source

/// <summary>
/// Get the elapsed time since the input DateTime
/// </summary>
/// <param name="input">Input DateTime</param>
/// <returns>Returns a TimeSpan value with the elapsed time since the input DateTime</returns>
/// <example>
/// TimeSpan elapsed = dtStart.Elapsed();
/// </example>
/// <seealso cref="ElapsedSeconds()"/>
public static TimeSpan Elapsed(this DateTime input)
{
        return DateTime.Now.Subtract(input);
}

Example

DateTime dtStart = DateTime.Now;
// Do something
Console.WriteLine(dtStart.Elapsed().TotalMilliseconds);

Author: Jonnidip

Submitted on: 30 nov. 2010

Language: C#

Type: System.DateTime

Views: 6623