CSharp examples for System:TimeSpan
Return a TimeSpan object representing the time differential between the specified start and end TimeSpan objects.
using System.Collections; using System;// ww w . j av a 2 s. c o m public class Main{ /// <summary> /// Return a TimeSpan object representing the time differential /// between the specified start and end TimeSpan objects. /// </summary> /// <param name="begin">The TimeSpan object representing the start</param> /// <param name="end">The TimeSpan object represending the end</param> /// <returns>A TimeSpan object representing the total differential</returns> public static TimeSpan Delta(TimeSpan begin, TimeSpan end) { TimeSpan diff = end.Subtract(begin); return diff; } #endregion #region -------- GET TIME DELTA -------- /// <summary> /// Return a TimeSpan object representing the time differential /// between the specified start and end times. /// </summary> /// <param name="begin">The DateTime object representing the start</param> /// <param name="end">The DateTime object represending the end</param> /// <returns>A TimeSpan object representing the total differential</returns> public static TimeSpan Delta(DateTime begin, DateTime end) { TimeSpan start = new TimeSpan(begin.Ticks); TimeSpan stop = new TimeSpan(end.Ticks); TimeSpan diff = stop.Subtract(start); return diff; } }