Gets the time span till now. - CSharp System

CSharp examples for System:TimeSpan

Description

Gets the time span till now.

Demo Code


using System.Globalization;
using System;//  w  ww . j a v a 2s .co m

public class Main{
        /// <summary>
        ///     Gets the time span till now.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public static TimeSpan GetTimeSpanTillNow(this DateTime? input)
        {
            return new TimeSpan(DateTime.Now.Ticks - Convert.ToDateTime(input).Ticks);
        }
        /// <summary>
        ///     Gets the time span till now.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public static TimeSpan GetTimeSpanTillNow(this DateTime input)
        {
            return new TimeSpan(DateTime.Now.Ticks - input.Ticks);
        }
}

Related Tutorials