The time delta (in ticks) between the given start and end dates - CSharp System

CSharp examples for System:DateTime Time

Description

The time delta (in ticks) between the given start and end dates

Demo Code


using System.Collections;
using System;/*  www .j a v a  2  s  .c o m*/

public class Main{
        /// <summary>
        /// The time delta (in ticks) between the given start and end dates
        /// </summary>
        /// <param name="begin">The DateTime object representing the start</param>
        /// <param name="end">The DateTime object represending the end</param>
        /// <returns>A long representing the total number of ticks between the two dates</returns>
        public static string GetSpanLength(DateTime begin, DateTime end) {
            TimeSpan start = new TimeSpan(begin.Ticks);
            TimeSpan stop = new TimeSpan(end.Ticks);
            TimeSpan diff = stop.Subtract(start);
            return Convert.ToString(Convert.ToInt32(diff.TotalHours)) + " hours, " + Convert.ToString(Convert.ToInt32(diff.TotalMinutes)) + " minutes, " + Convert.ToString(diff.TotalSeconds) + " seconds";
        }
}

Related Tutorials