System.Globalization.GregorianCalendar.GetDayOfWeek C# (CSharp) Method

GetDayOfWeek() public method

public GetDayOfWeek ( System.DateTime time ) : DayOfWeek
time System.DateTime
return DayOfWeek
        public override DayOfWeek GetDayOfWeek(DateTime time)
        {
            return ((DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7));
        }

Usage Example

Example #1
0
        /// <summary>
        /// Returns the daylight changes for UTC (never).
        /// </summary>
        public override DaylightTime GetDaylightChanges(int year)
        {
            // We need a start and stop time
            DateTime start, end;
            Calendar cal = new GregorianCalendar();

            // 2007+ at this point has a slightly different start/stop
            if (year >= 2007)
            {
                start = new DateTime(year, 4, 1, 2, 0, 0);
                end = new DateTime(year, 11, 1, 2, 0, 0);
            }
            else
            {
                start = new DateTime(year, 3, 1, 2, 0, 0);
                end = new DateTime(year, 12, 1, 2, 0, 0);
            }

            // Move forward for the start date until we have a sunday
            while (cal.GetDayOfWeek(start) != DayOfWeek.Sunday)
                start = cal.AddDays(start, 1);

            // Move backwards from the end date to the last sunday
            while (cal.GetDayOfWeek(end) != DayOfWeek.Sunday)
                start = cal.AddDays(end, 1);

            // Create it
            return new DaylightTime(start, end,
                new TimeSpan(stOffset - dtOffset, 0, 0));
        }
All Usage Examples Of System.Globalization.GregorianCalendar::GetDayOfWeek