当前位置: 首页>>代码示例>>C#>>正文


C# Calendar.AddDays方法代码示例

本文整理汇总了C#中System.Globalization.Calendar.AddDays方法的典型用法代码示例。如果您正苦于以下问题:C# Calendar.AddDays方法的具体用法?C# Calendar.AddDays怎么用?C# Calendar.AddDays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Globalization.Calendar的用法示例。


在下文中一共展示了Calendar.AddDays方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEraRanges

        /// <summary>
        /// Builds an array of <see cref="MonthCalendarEraRange"/> to store the min and max date of the eras of the specified
        /// <see cref="System.Globalization.Calendar"/>.
        /// </summary>
        /// <param name="cal">
        /// The <see cref="System.Globalization.Calendar"/> to retrieve the era ranges for.
        /// </param>
        /// <returns>
        /// An array of type <see cref="MonthCalendarEraRange"/>.
        /// </returns>
        private static MonthCalendarEraRange[] GetEraRanges(Calendar cal)
        {
            if (cal.Eras.Length == 1)
            {
                return new[] { new MonthCalendarEraRange(cal.Eras[0], cal.MinSupportedDateTime.Date, cal.MaxSupportedDateTime.Date) };
            }

            List<MonthCalendarEraRange> ranges = new List<MonthCalendarEraRange>();
            DateTime date = cal.MinSupportedDateTime.Date;
            int currentEra = -1;
            while (date < cal.MaxSupportedDateTime.Date)
            {
                int era = cal.GetEra(date);

                if (era != currentEra)
                {
                    ranges.Add(new MonthCalendarEraRange(era, date));
                    if (currentEra != -1)
                    {
                        ranges[ranges.Count - 2].MaxDate = cal.AddDays(date, -1);
                    }

                    currentEra = era;
                }

                date = cal.AddDays(date, 1);
            }

            ranges[ranges.Count - 1].MaxDate = date;
            return ranges.ToArray();
        }
开发者ID:tu-tran,项目名称:FareLiz,代码行数:41,代码来源:EnhancedMonthCalendar.cs

示例2: IsValidYear

      /// <summary>
      /// Determines if the specified <paramref name="year"/> is a valid year value.
      /// </summary>
      /// <param name="year">The year value.</param>
      /// <param name="cal">The calendar to use.</param>
      /// <param name="era">The era the year belongs to.</param>
      /// <returns>true if it's a valid year value; false otherwise.</returns>
      private static bool IsValidYear(int year, Calendar cal, int era)
      {
         int minYear = cal.GetYear(cal.MinSupportedDateTime.Date);
         int maxYear = cal.GetYear(cal.MaxSupportedDateTime.Date);

         if (cal.Eras.Length > 1)
         {
            DateTime? minDate = null, maxDate = null;

            DateTime date = cal.MinSupportedDateTime;

            while (date < cal.MaxSupportedDateTime.Date)
            {
               int e = cal.GetEra(date);

               if (e == era)
               {
                  if (minDate == null)
                  {
                     minDate = date;
                  }

                  maxDate = date;
               }

               date = cal.AddDays(date, 1);
            }

            minYear = cal.GetYear(minDate.GetValueOrDefault(cal.MinSupportedDateTime.Date));
            maxYear = cal.GetYear(maxDate.GetValueOrDefault(cal.MaxSupportedDateTime.Date));
         }

         year = cal.ToFourDigitYear(year);

         return year >= minYear && year <= maxYear;
      }
开发者ID:sulerzh,项目名称:DbExporter,代码行数:43,代码来源:DatePickerDateTextBox.cs

示例3: WeekListEventHandler

        private void WeekListEventHandler(Object source, ListCommandEventArgs e)
        {
            // Get the first calendar day and adjust it to the week the user
            // selected (to be consistent with the index setting in Render())
            _threadCalendar = DateTimeFormatInfo.CurrentInfo.Calendar;

            DateTime tempDate = FirstCalendarDay(Control.VisibleDate);

            Control.VisibleDate = _threadCalendar.AddDays(tempDate, e.ListItem.Index * 7);

            if (_chooseOption == WeekOption)
            {
                // Add the whole week to the date list
                DateTime endDate = _threadCalendar.AddDays(Control.VisibleDate, 6);

                SelectRange(Control.VisibleDate, endDate);
                HandlePostBackEvent(Done.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                SecondaryUIMode = ChooseDay;
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:23,代码来源:ChtmlCalendarAdapter.cs

示例4: DayListEventHandler

        private void DayListEventHandler(Object source, ListCommandEventArgs e)
        {
            _threadCalendar = DateTimeFormatInfo.CurrentInfo.Calendar;

            // VisibleDate should have been set with the first day of the week
            // so the selected index can be used to adjust to the selected day.
            Control.VisibleDate = _threadCalendar.AddDays(Control.VisibleDate, e.ListItem.Index);

            SelectRange(Control.VisibleDate, Control.VisibleDate);
            HandlePostBackEvent(Done.ToString(CultureInfo.InvariantCulture));
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:ChtmlCalendarAdapter.cs

示例5: MonthListEventHandler

        private void MonthListEventHandler(Object source, ListCommandEventArgs e)
        {
            _threadCalendar = DateTimeFormatInfo.CurrentInfo.Calendar;

            if (e.ListItem.Index == _monthsToDisplay)
            {
                // Next was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                                        Control.VisibleDate, _monthsToDisplay);
                SecondaryUIMode = ChooseMonth;
            }
            else if (e.ListItem.Index == _monthsToDisplay + 1)
            {
                // Prev was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                                        Control.VisibleDate, -_monthsToDisplay);
                SecondaryUIMode = ChooseMonth;
            }
            else
            {
                // A month was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                                        Control.VisibleDate,
                                        e.ListItem.Index);

                if (_chooseOption == MonthOption)
                {
                    // Add the whole month to the date list
                    DateTime beginDate = EffectiveVisibleDate(Control.VisibleDate);
                    Control.VisibleDate = beginDate;

                    DateTime endDate = _threadCalendar.AddMonths(beginDate, 1);
                    endDate = _threadCalendar.AddDays(endDate, -1);

                    SelectRange(beginDate, endDate);
                    HandlePostBackEvent(Done.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    SecondaryUIMode = ChooseWeek;
                }
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:43,代码来源:ChtmlCalendarAdapter.cs

示例6: Render


//.........这里部分代码省略.........
                        tempDate = _threadCalendar.AddMonths(tempDate, 1);
                    }
                    arr.Add(GetDefaultLabel(NextLabel));
                    arr.Add(GetDefaultLabel(PreviousLabel));

                    DataBindAndRender(writer, _monthList, arr);
                    break;

                // Based on the month selected in case ChooseMonth above, render a list of
                // availabe weeks of the month.
                case ChooseWeek:
                    String monthFormat = (GetNumericDateFormat()[0] == 'y') ? "yyyy/M" : "M/yyyy";
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseWeek));
                    writer.Write(" (");
                    writer.Write(Control.VisibleDate.ToString(monthFormat, CultureInfo.CurrentCulture));
                    writer.Write("):");
                    writer.WriteBreak();

                    // List weeks of days of the selected month.  May include
                    // days from the previous and the next month to fill out
                    // all six week choices.  This is consistent with the
                    // ASP.NET Calendar control.

                    // Note that the event handling code of this list control
                    // should be implemented according to the index content
                    // generated here.

                    tempDate = FirstCalendarDay(Control.VisibleDate);

                    arr = new ArrayList();
                    String weekDisplay;
                    for (int i = 0; i < 6; i++)
                    {
                        weekDisplay = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                        weekDisplay += DaySeparator;
                        tempDate = _threadCalendar.AddDays(tempDate, 6);
                        weekDisplay += tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                        arr.Add(weekDisplay);
                        tempDate = _threadCalendar.AddDays(tempDate, 1);
                    }

                    DataBindAndRender(writer, _weekList, arr);
                    break;

                // Based on the month and week selected in case ChooseMonth and ChooseWeek above,
                // render a list of the dates in the week.
                case ChooseDay:
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseDate));
                    writer.Write(":");
                    writer.WriteBreak();

                    tempDate = Control.VisibleDate;

                    arr = new ArrayList();
                    String date;
                    String dayName;
                    StringBuilder dayDisplay = new StringBuilder();
                    bool dayNameFirst = (GetNumericDateFormat()[0] != 'y');

                    for (int i = 0; i < 7; i++)
                    {
                        date = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);

                        if (Control.ShowDayHeader)
                        {
                            // Use the short format for displaying day name
                            dayName = GetAbbreviatedDayName(tempDate);
                            dayDisplay.Length = 0;

                            if (dayNameFirst)
                            {
                                dayDisplay.Append(dayName);
                                dayDisplay.Append(Space);
                                dayDisplay.Append(date);
                            }
                            else
                            {
                                dayDisplay.Append(date);
                                dayDisplay.Append(Space);
                                dayDisplay.Append(dayName);
                            }
                            arr.Add(dayDisplay.ToString());
                        }
                        else
                        {
                            arr.Add(date);
                        }
                        tempDate = _threadCalendar.AddDays(tempDate, 1);
                    }

                    DataBindAndRender(writer, _dayList, arr);
                                        break;

                default:
                    Debug.Assert(false, "Unexpected Secondary UI Mode");
                                        break;
            }

            writer.ExitStyle(Style, breakAfter);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:ChtmlCalendarAdapter.cs

示例7: DeferOccurrenceFallingOnWeekend

 private static DateTime DeferOccurrenceFallingOnWeekend(Calendar calendar, DateTime occurrence, bool skipWeekends = true)
 {
     if(skipWeekends)
     {
         if (occurrence.DayOfWeek == DayOfWeek.Saturday)
         {
             occurrence = calendar.AddDays(occurrence, 2);
         }
         if (occurrence.DayOfWeek == DayOfWeek.Sunday)
         {
             occurrence = calendar.AddDays(occurrence, 1);
         }    
     }
     
     return occurrence.ToUniversalTime();
 }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:16,代码来源:DatePeriod.cs

示例8: GetOccurrences

        private static IEnumerable<DateTime> GetOccurrences(DateInterval interval, DatePeriod period, Calendar calendar, DateTime start, DateTime end, bool skipWeekends = true)
        {
            var difference = DateSpan.GetDifference(interval, start, end)/period.Quantifier;

            if (start.Kind == DateTimeKind.Utc)
            {
                start = start.ToLocalTime();
            }

            for (var i = 0; i < difference; i++)
            {
                switch (period.Frequency)
                {
                    case DatePeriodFrequency.Seconds:
                        var seconds = calendar.AddSeconds(start, period.Quantifier * i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, seconds, skipWeekends);
                        break;
                    case DatePeriodFrequency.Minutes:
                        var minutes = calendar.AddMinutes(start, period.Quantifier * i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, minutes, skipWeekends);
                        break;
                    case DatePeriodFrequency.Hours:
                        var hours = calendar.AddHours(start, period.Quantifier * i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, hours, skipWeekends);
                        break;
                    case DatePeriodFrequency.Days:
                        var days = calendar.AddDays(start, period.Quantifier*i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, days, skipWeekends);
                        break;
                    case DatePeriodFrequency.Weeks:
                        var weeks = calendar.AddWeeks(start, period.Quantifier*i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, weeks, skipWeekends);
                        break;
                    case DatePeriodFrequency.Months:
                        var months = calendar.AddMonths(start, period.Quantifier*i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, months, skipWeekends);
                        break;
                    case DatePeriodFrequency.Years:
                        var years = calendar.AddYears(start, period.Quantifier*i);
                        yield return DeferOccurrenceFallingOnWeekend(calendar, years, skipWeekends);
                        break;
                    default:
                        throw new ArgumentException("Frequency");
                }
            }
        }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:46,代码来源:DatePeriod.cs

示例9: GetFirstDayOfWeek

        /// <summary>
        /// Gets the first day of a week.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="week">The week.</param>
        /// <param name="calendar">The calendar.</param>
        /// <param name="calendarWeekRule">The calendar week rule.</param>
        /// <param name="firstDayOfWeek">The first day of week.</param>
        /// <returns>The date of the first day in the week.</returns>
        public static DateTime GetFirstDayOfWeek(
                int year,
                int week,
                Calendar calendar = null,
                CalendarWeekRule calendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
                DayOfWeek firstDayOfWeek = DayOfWeek.Sunday)
        {
            if (calendar == null)
                calendar = CultureInfo.CurrentCulture.Calendar;

            DateTime firstDay = new DateTime(year, 1, 7, calendar);

            while (calendar.GetDayOfWeek(firstDay) != firstDayOfWeek || WeekNumber(firstDay, calendar, calendarWeekRule, firstDayOfWeek) % 52 > 1)
            {
                firstDay = calendar.AddDays(firstDay, -1);
            }

            // Add the week
            return (week != 1) ? calendar.AddWeeks(firstDay, week - 1) : firstDay;
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:29,代码来源:ScheduleExtensions.cs


注:本文中的System.Globalization.Calendar.AddDays方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。