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


C# DateTime.AddMonths方法代码示例

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


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

示例1: InstantToDateTime

            public static DateTime InstantToDateTime(double instant, DateTime start, TimeUnits units = TimeUnits.SECONDS)
            {
                DateTime instantAsDate = start;

                switch (units)
                {
                   case TimeUnits.YEARS:
                  instantAsDate = start.AddYears((int)instant);
                  break;
                   case TimeUnits.MONTHS:
                  instantAsDate = start.AddMonths((int)instant);
                  break;
                   case TimeUnits.DAYS:
                  instantAsDate = start.AddDays(instant);
                  break;
                   case TimeUnits.HOURS:
                  instantAsDate = start.AddHours(instant);
                  break;
                   case TimeUnits.MINUTES:
                  instantAsDate = start.AddMinutes(instant);
                  break;
                   case TimeUnits.SECONDS:
                  instantAsDate = start.AddSeconds(instant);
                  break;
                }

                return instantAsDate;
            }
开发者ID:JauchOnGitHub,项目名称:csharptoolbox,代码行数:28,代码来源:Conversions.cs

示例2: EndOfCurrentmonth

        public static DateTime EndOfCurrentmonth(this DateTime value)
        {
            var retVal = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 01);

            retVal = retVal.AddMonths(1).AddDays(-1);
            return new DateTime(retVal.Year, retVal.Month, retVal.Day);
        }
开发者ID:s-leonard,项目名称:Tarts,代码行数:7,代码来源:DateTimeExtentions.cs

示例3: IsThisMonth

        /// <summary>
        /// Returns true if the date is this month's date.
        /// </summary>
        public static bool IsThisMonth(this DateTime time)
        {
            DateTime now = DateTime.UtcNow;
             DateTime monthStart = new DateTime(now.Year, now.Month, 1);
             DateTime monthEnd = monthStart.AddMonths(1);

             return time > monthStart && time < monthEnd;
        }
开发者ID:aloneguid,项目名称:support,代码行数:11,代码来源:DateTimeExtensions.cs

示例4: CanAddMonthsAcrossDstTransition

        public void CanAddMonthsAcrossDstTransition()
        {
            var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dt = new DateTime(2015, 2, 9, 0, 0, 0);
            var result = dt.AddMonths(1, tz);

            var expected = new DateTimeOffset(2015, 3, 9, 0, 0, 0, TimeSpan.FromHours(-7));
            Assert.Equal(expected, result);
            Assert.Equal(expected.Offset, result.Offset);
        }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:10,代码来源:DateTimeTests.cs

示例5: DrawMonthCalendarDate

		// draws one day in the calendar grid
		private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc,	DateTime date, DateTime month, int row, int col) {
			Color date_color = mc.ForeColor;
			Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));

			// find out if we are the lead of the first calendar or the trail of the last calendar						
			if (date.Year != month.Year || date.Month != month.Month) {
				DateTime check_date = month.AddMonths (-1);
				// check if it's the month before 
				if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
					date_color = mc.TrailingForeColor;
				} else {
					// check if it's the month after
					check_date = month.AddMonths (1);
					if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
						date_color = mc.TrailingForeColor;
					} else {
						return;
					}
				}
			} else {
				date_color = mc.ForeColor;
			}

			const int inflate = -1;

			if (date == mc.SelectionStart.Date && date == mc.SelectionEnd.Date) {
				// see if the date is in the start of selection
				date_color = mc.BackColor;
				// draw the left hand of the back ground
				Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);				
				dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 360);
			} else if (date == mc.SelectionStart.Date) {
				// see if the date is in the start of selection
				date_color = mc.BackColor;
				// draw the left hand of the back ground
				Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);				
				dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
				// fill the other side as a straight rect
				if (date < mc.SelectionEnd.Date) 
				{
					// use rectangle instead of rectangle to go all the way to edge of rect
					selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
					selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
					dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
				}
			} else if (date == mc.SelectionEnd.Date) {
				// see if it is the end of selection
				date_color = mc.BackColor;
				// draw the left hand of the back ground
				Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
				dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
				// fill the other side as a straight rect
				if (date > mc.SelectionStart.Date) {
					selection_rect.X = rectangle.X;
					selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
					dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
				}
			} else if (date > mc.SelectionStart.Date && date < mc.SelectionEnd.Date) {
				// now see if it's in the middle
				date_color = mc.BackColor;
				// draw the left hand of the back ground
				Rectangle selection_rect = Rectangle.Inflate (rectangle, 0, inflate);
				dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
			}

			// establish if it's a bolded font
			Font font = mc.IsBoldedDate (date) ? mc.bold_font : mc.Font;

			// just draw the date now
			dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, mc.centered_format);

			// today circle if needed
			if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
				DrawTodayCircle (dc, interior);
			}

			// draw the selection grid
			if (mc.is_date_clicked && mc.clicked_date == date) {
				Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
				dc.DrawRectangle (pen, interior);
			}
		}
开发者ID:ngraziano,项目名称:mono,代码行数:83,代码来源:ThemeWin32Classic.cs

示例6: AddMonths

 public void AddMonths(DateTime time, int months)
 {
     Assert.Equal(time.AddMonths(months), new KoreanCalendar().AddMonths(time, months));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:4,代码来源:KoreanCalendarAddMonths.cs

示例7: DateAndTimeOfDayModelContext

        static DateAndTimeOfDayModelContext()
        {
            DateTime dt = new DateTime(2014, 12, 31);

            _dateTimes = Enumerable.Range(1, 5).Select(i =>
                new DateAndTimeOfDayModel
                {
                    Id = i,
                    Birthday = dt.AddYears(i),
                    PublishDay = i % 2 == 0 ? (DateTime?)null : dt.AddMonths(i),
                    CreatedTime = new TimeSpan(0, i, 4, 5, 198),
                    EdmTime = i % 3 == 0 ? (TimeSpan?)null : new TimeSpan(0, 8, i, 5, 198),
                    ResumeTime = new TimeSpan(0, i, 4, 5, 198)
                }).ToList();
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:15,代码来源:DateAndTimeOfDayTest.cs

示例8: AddMonths

 public void AddMonths(DateTime time, int months)
 {
     Assert.Equal(time.AddMonths(months), new ThaiBuddhistCalendar().AddMonths(time, months));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:4,代码来源:ThaiBuddhistCalendarAddMonths.cs

示例9: DisplayDateRangeEnd

        public void DisplayDateRangeEnd()
        {
            Calendar calendar = new Calendar();
            DateTime value = new DateTime(2000, 1, 30);
            calendar.DisplayDate = value;
            calendar.DisplayDateEnd = value;
            calendar.DisplayDateStart = value;
            Assert.IsTrue(CompareDates(calendar.DisplayDateStart.Value, value));
            Assert.IsTrue(CompareDates(calendar.DisplayDateEnd.Value, value));

            value = value.AddMonths(2);
            calendar.DisplayDateStart = value;

            Assert.IsTrue(CompareDates(calendar.DisplayDateStart.Value, value));
            Assert.IsTrue(CompareDates(calendar.DisplayDateEnd.Value, value));
            Assert.IsTrue(CompareDates(calendar.DisplayDate, value));
        }
开发者ID:dfr0,项目名称:moon,代码行数:17,代码来源:CalendarTest.cs

示例10: DateTimeModelContext

        static DateTimeModelContext()
        {
            DateTime dt = new DateTime(2014, 12, 31, 20, 12, 30, DateTimeKind.Utc);

            _dateTimes = Enumerable.Range(1, 5).Select(i =>
                new DateTimeModel
                {
                    Id = i,
                    BirthdayA = dt.AddYears(i),
                    BirthdayB = dt.AddMonths(i),
                    BirthdayC = new List<DateTime> { dt.AddYears(i), dt.AddMonths(i), dt.AddDays(i) },
                    BirthdayD = new List<DateTime?>
                    {
                        dt.AddYears(2 * i), null, dt.AddMonths(2 * i)
                    }
                }).ToList();
        }
开发者ID:billwaddyjr,项目名称:WebApi,代码行数:17,代码来源:DateTimeTest.cs


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