Returns a date in the past by hours. - CSharp System

CSharp examples for System:DateTime Hour

Description

Returns a date in the past by hours.

Demo Code

//   The contents of this file are subject to the New BSD
using System;//from   www .  j a v  a2  s.  com

public class Main{
        /// <summary>
    /// Returns a date in the past by hours.
    /// </summary>
    /// <param name="hours">The hours.</param>
    /// <returns></returns>
    public static DateTime HoursAgo(this int hours) {
        TimeSpan t = new TimeSpan(hours, 0, 0);
        return DateTime.Now.Subtract(t);
    }
}

Related Tutorials