CSharp examples for System:DateTime Second
Sets the hour, minute, second and millisecond to zero.
using System;// w ww. j a v a 2 s. c o m public class Main{ /// <summary> /// Sets the hour, minute, second and millisecond to zero. /// </summary> /// <param name="dateTime">DateTime which time must be removed.</param> /// <returns>Returns only the date from the DateTimeOffset.</returns> public static DateTimeOffset RemoveTime(this DateTimeOffset dateTime) { DateTimeOffset newDateTime = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, 00, 00, 00, dateTime.Offset); return newDateTime; } #endregion #region RemoveTime /// <summary> /// Sets the hour, minute, second and millisecond to zero. /// </summary> /// <param name="dateTime">DateTime which time must be removed.</param> /// <returns>Returns only the date from the DateTime.</returns> public static DateTime RemoveTime(this DateTime dateTime) { DateTime newDateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 00, 00, 00, dateTime.Kind); return newDateTime; } }