CSharp examples for System:DateTime Second
To Nearest Second
using System;/*from w w w . j av a 2s .c om*/ public class Main{ public static DateTime ToNearestSecond(this DateTime dateTime) { return dateTime.Truncate(TimeSpan.FromSeconds(1)); } private static DateTime Truncate(this DateTime dateTime, TimeSpan timeSpan) { if (timeSpan == TimeSpan.Zero) { return dateTime; } return dateTime.AddTicks(-(dateTime.Ticks%timeSpan.Ticks)); } }