AddMonths() public méthode

public AddMonths ( [ months ) : void
months [
Résultat void
        private void ShowResults()
        {
            // This scenario illustrates time zone support in Windows.Globalization.Calendar class

            // Displayed time zones in addition to the local time zone.
            string[] timeZones = new[] { "UTC", "America/New_York", "Asia/Kolkata" };

            // Store results here.
            StringBuilder results = new StringBuilder();

            // Create default Calendar object
            Calendar calendar = new Calendar();
            string localTimeZone = calendar.GetTimeZone();

            // Show current time in local time zone
            results.AppendLine("Current date and time:");
            results.AppendLine(ReportCalendarData(calendar));

            // Show current time in additional time zones
            foreach (string timeZone in timeZones)
            {
                calendar.ChangeTimeZone(timeZone);
                results.AppendLine(ReportCalendarData(calendar));
            }
            results.AppendLine();

            // Change back to local time zone
            calendar.ChangeTimeZone(localTimeZone);

            // Show a time on 14th day of second month of next year.
            // Note the effect of daylight saving time on the results.
            results.AppendLine("Same time on 14th day of second month of next year:");
            calendar.AddYears(1); calendar.Month = 2; calendar.Day = 14;
            results.AppendLine(ReportCalendarData(calendar));
            foreach (string timeZone in timeZones)
            {
                calendar.ChangeTimeZone(timeZone);
                results.AppendLine(ReportCalendarData(calendar));
            }
            results.AppendLine();

            // Change back to local time zone
            calendar.ChangeTimeZone(localTimeZone);

            // Show a time on 14th day of tenth month of next year.
            // Note the effect of daylight saving time on the results.
            results.AppendLine("Same time on 14th day of tenth month of next year:");
            calendar.AddMonths(8);
            results.AppendLine(ReportCalendarData(calendar));
            foreach (string timeZone in timeZones)
            {
                calendar.ChangeTimeZone(timeZone);
                results.AppendLine(ReportCalendarData(calendar));
            }
            results.AppendLine();

            // Display the results
            OutputTextBlock.Text = results.ToString();
        }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario illustrates TimeZone support in Windows.Globalization.Calendar class

            // Displayed TimeZones (other than local timezone)
            String[] timeZones = new String[] { "UTC", "America/New_York", "Asia/Kolkata" };

            // Store results here.
            StringBuilder results = new StringBuilder();

            // Create default Calendar object
            Calendar calendar = new Calendar();
            String localTimeZone = calendar.GetTimeZone();

            // Show current time in timezones desired to be displayed including local timezone
            results.AppendLine("Current date and time -");
            results.AppendLine(GetFormattedCalendarDateTime(calendar));
            foreach (String timeZone in timeZones)
            {
                calendar.ChangeTimeZone(timeZone);
                results.AppendLine(GetFormattedCalendarDateTime(calendar));
            }
            results.AppendLine();
            calendar.ChangeTimeZone(localTimeZone);

            // Show a time on 14th day of second month of next year in local, GMT, New York and Indian Time Zones
            // This will show if there were day light savings in time
            results.AppendLine("Same time on 14th day of second month of next year -");
            calendar.AddYears(1); calendar.Month = 2; calendar.Day = 14;
            results.AppendLine(GetFormattedCalendarDateTime(calendar));
            foreach (String timeZone in timeZones)
            {
                calendar.ChangeTimeZone(timeZone);
                results.AppendLine(GetFormattedCalendarDateTime(calendar));
            }
            results.AppendLine();
            calendar.ChangeTimeZone(localTimeZone);

            // Show a time on 14th day of 10th month of next year in local, GMT, New York and Indian Time Zones
            // This will show if there were day light savings in time
            results.AppendLine("Same time on 14th day of tenth month of next year -");
            calendar.AddMonths(8);
            results.AppendLine(GetFormattedCalendarDateTime(calendar));
            foreach (String timeZone in timeZones)
            {
                calendar.ChangeTimeZone(timeZone);
                results.AppendLine(GetFormattedCalendarDateTime(calendar));
            }
            results.AppendLine();

            // Display the results
            rootPage.NotifyUser(results.ToString(), NotifyType.StatusMessage);
        }
        private async void BindData(int index)
        {
            var calendar = new Calendar();
            calendar.AddMonths(index);

            CurrentMonth = calendar.MonthAsString();
            CurrentYear = calendar.YearAsString();

            // Save month.
            GlobalData.SelectedMonthIndex = calendar.Month;

            var fDayOfThisMonth = new DateTime(calendar.Year, calendar.Month, calendar.FirstDayInThisMonth);
            var fbuffer = CalcBuffer(fDayOfThisMonth);

            // Save this value to draw grid of month later
            GlobalData.NumberOfRows = NumberOfRowsForMonth(calendar, fDayOfThisMonth);

            var lDayOfThisMonth = new DateTime(calendar.Year, calendar.Month, calendar.LastDayInThisMonth);
            var lbuffer = CalcBuffer(lDayOfThisMonth, true);

            calendar.AddMonths(-1);

            var temp = new List<DayItemModel>();
            // Add pre buffer
            for (var i = 1; i <= fbuffer; i++)
            {
                var dim = new DayItemModel
                    {
                        Today = new DateTime(calendar.Year, calendar.Month, calendar.LastDayInThisMonth - (fbuffer - i)),
                    };
                dim.TaskList = await TaskRepository.Instance.GetTaskListFor(dim.Today);
                temp.Add(dim);
            }

            calendar.AddMonths(1);
            // Add month
            for (var i = 0; i < lDayOfThisMonth.Day; i++)
            {
                var dim = new DayItemModel
                    {
                        Today = new DateTime(calendar.Year, calendar.Month, calendar.FirstDayInThisMonth + i)
                    };
                dim.TaskList = await TaskRepository.Instance.GetTaskListFor(dim.Today);

                temp.Add(dim);
            }

            calendar.AddMonths(1);
            // Add post buffer
            for (var i = 0; i < lbuffer; i++)
            {
                var dim = new DayItemModel
                    {
                        Today = new DateTime(calendar.Year, calendar.Month, calendar.FirstDayInThisMonth + i)
                    };
                dim.TaskList = await TaskRepository.Instance.GetTaskListFor(dim.Today);

                temp.Add(dim);
            }

            SingleMonth = temp;
        }