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


C# Calendar.AddMonths方法代码示例

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


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

示例1: 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

示例2: Render


//.........这里部分代码省略.........
                    // Command button for sending the textbox value back to the server
                    _command.Text = GetDefaultLabel(OKLabel);
                    _command.Visible = true;
                    _command.RenderControl(writer);

                    break;

                // Render a paged list for choosing a month
                case ChooseMonth:
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                    writer.Write(":");
                    writer.WriteBreak();

                    tempDate = Control.VisibleDate;

                    String abbreviatedYearMonthPattern = AbbreviateMonthPattern(currentDateTimeInfo.YearMonthPattern);

                    // This is to be consistent with ASP.NET Calendar control
                    // on handling YearMonthPattern:
                    // Some cultures have a comma in their YearMonthPattern,
                    // which does not look right in a calendar.  Here we
                    // strip the comma off.
                    int indexComma = abbreviatedYearMonthPattern.IndexOf(',');
                    if (indexComma >= 0)
                    {
                        abbreviatedYearMonthPattern =
                            abbreviatedYearMonthPattern.Remove(indexComma, 1);
                    }

                    arr = new ArrayList();
                    for (int i = 0; i < _monthsToDisplay; i++)
                    {
                        arr.Add(tempDate.ToString(abbreviatedYearMonthPattern, CultureInfo.CurrentCulture));
                        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++)
                    {
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:67,代码来源:ChtmlCalendarAdapter.cs

示例3: EndOfSemester

        public static DateTime EndOfSemester( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( Contract.Result<DateTime>().Semester( calendar ) == Contract.OldValue( date.Semester( calendar ) ) );

            return calendar.AddMonths( date.StartOfSemester( calendar ), 6 ).AddTicks( -1L );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:DateTimeExtensions.cs

示例4: 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

示例5: StartOfSemester

        public static DateTime StartOfSemester( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( Contract.Result<DateTime>().Semester( calendar ) == Contract.OldValue( date.Semester( calendar ) ) );

            var semester = date.Semester( calendar );
            return calendar.AddMonths( date.StartOfYear( calendar ), ( semester - 1 ) * 6 );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:9,代码来源:DateTimeExtensions.cs


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