CSharp examples for System:DateTime Second
Sets the milliseconds to zero.
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; } }