Returns the very end of the given month (the last millisecond of the last hour for the given date) - CSharp System

CSharp examples for System:DateTime Second

Description

Returns the very end of the given month (the last millisecond of the last hour for the given date)

Demo Code


using System;//from w  ww .j  av a2s  . co m

public class Main{
        /// <summary>
        /// Returns the very end of the given month (the last millisecond of the last hour for the given date)
        /// </summary>
        /// <param name="obj">DateTime Base, from where the calculation will be preformed.</param>
        /// <returns>Returns the very end of the given month (the last millisecond of the last hour for the given date)</returns>
        public static DateTime EndOfMonth(this DateTime obj)
        {
            return new DateTime(obj.Year, obj.Month, DateTime.DaysInMonth(obj.Year, obj.Month), 23, 59, 59, 999);
        }
}

Related Tutorials