Sets the milliseconds to zero. - CSharp System

CSharp examples for System:DateTime Second

Description

Sets the milliseconds to zero.

Demo Code


using System;/*from  w w  w .  j a v  a2  s  .  co m*/

public class Main{
        /// <summary>
        /// Sets the milliseconds to zero.
        /// </summary>
        /// <param name="dateTime">DateTimeOffset which milliseconds must be set to zero.</param>
        /// <returns>Returns the DateTimeOffset without milliseconds.</returns>
        public static DateTimeOffset RemoveMilliseconds(this DateTimeOffset dateTime)
        {
            DateTimeOffset newDateTime = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day,
                dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Offset);
            return newDateTime;
        }
        #endregion

        #region RemoveMilliseconds
        /// <summary>
        /// Sets the milliseconds to zero.
        /// </summary>
        /// <param name="dateTime">DateTime which milliseconds must be set to zero.</param>
        /// <returns>Returns the DateTime without milliseconds.</returns>
        public static DateTime RemoveMilliseconds(this DateTime dateTime)
        {
            DateTime newDateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
                dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind);
            return newDateTime;
        }
}

Related Tutorials