Round DateTime value - CSharp System

CSharp examples for System:DateTime Calculate

Description

Round DateTime value

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from   w ww .j a  v  a  2 s .  c o m*/

public class Main{
        public static DateTime Round(this DateTime date, TimeSpan span)
        {
            long ticks = (date.Ticks + (span.Ticks / 2) + 1) / span.Ticks;
            return new DateTime(ticks * span.Ticks, date.Kind);
        }
}

Related Tutorials