Gets a date in the past according to seconds - CSharp System

CSharp examples for System:DateTime Second

Description

Gets a date in the past according to seconds

Demo Code

//   The contents of this file are subject to the New BSD
using System;//from w w  w. j  a va  2  s .c o m

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

Related Tutorials