Get Quarter Hour Increments After - CSharp System

CSharp examples for System:DateTime Quarter

Description

Get Quarter Hour Increments After

Demo Code


using Windows.Globalization.DateTimeFormatting;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//ww w.  ja  v  a 2  s .co  m

public class Main{
        public static IEnumerable<DateTime> GetQuarterHourIncrementsAfter(this DateTime dateTime, bool wrap = true)
        {
            var quarterHours = new List<DateTime>(QuarterHoursInDay);
            for (int i = 1; i <= QuarterHoursInDay; i++)
            {
                var newDateTime = dateTime.AddMinutes(i * 15);
                if (!wrap && newDateTime.Date.CompareTo(dateTime.Date) > 0)
                {
                    break;
                }

                quarterHours.Add(newDateTime);
            }

            return quarterHours;
        }
}

Related Tutorials