Round Down To Quarter Hour - CSharp System

CSharp examples for System:DateTime Quarter

Description

Round Down To Quarter Hour

Demo Code


using Windows.Globalization.DateTimeFormatting;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from www.  j a v a 2 s  . c o  m*/

public class Main{
        public static DateTime RoundDownToQuarterHour(this DateTime dateTime)
        {
            var newMinute = dateTime.Minute - (dateTime.Minute % 15);

            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0, 0, dateTime.Kind).AddMinutes(newMinute);
        }
}

Related Tutorials