Sets the time part to the latest time of the day. - CSharp System

CSharp examples for System:DateTime Day

Description

Sets the time part to the latest time of the day.

Demo Code

//     Copyright (c) Rico Suter. All rights reserved.
using System;//www.j  a  v  a 2s  . c  om

public class Main{
        /// <summary>Sets the time part to the latest time of the day. </summary>
        /// <param name="dt">The date time to work with. </param>
        /// <returns>The new date time. </returns>
        public static DateTime? ToEndOfDay(this DateTime? dt)
        {
            return dt.HasValue ? dt.Value.ToEndOfDay() : (DateTime?)null;
        }
        /// <summary>Sets the time part to the latest time of the day. </summary>
        /// <param name="dt">The date time to work with. </param>
        /// <returns>The new date time. </returns>
        public static DateTime ToEndOfDay(this DateTime dt)
        {
            return new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59, 999);
        }
}

Related Tutorials