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


C# DateTime.AddMonths方法代码示例

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


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

示例1: Add

 public static DateTime Add(DatePartType datePart, long add, DateTime dt)
 {
     switch (datePart) {
     case DatePartType.Year:
         return dt.AddYears ((int)add);
     case DatePartType.Quarter:
         return dt.AddMonths ((int)add * 3);
     case DatePartType.Month:
         return dt.AddMonths ((int)add);
     case DatePartType.Day:
     case DatePartType.DayOfYear:
     case DatePartType.DayOfWeek:
         return dt.AddDays (add);
     case DatePartType.Hour:
         return dt.AddHours (add);
     case DatePartType.Minute:
         return dt.AddMinutes (add);
     case DatePartType.Second:
         return dt.AddSeconds (add);
     case DatePartType.MilliSecond:
         return dt.AddMilliseconds (add);
     case DatePartType.MicroSecond:
         return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000);
     case DatePartType.NanoSecond:
         return dt.AddTicks (add * TimeSpan.TicksPerMillisecond / 1000000);
     default:
         throw new InvalidOperationException (string.Format ("Unknown DatePart type '{0}'", datePart));
     }
 }
开发者ID:WimObiwan,项目名称:FxGqlC,代码行数:29,代码来源:DateFunctionsHelper.cs

示例2: CanCalculateRecurrenceSet

            public void CanCalculateRecurrenceSet()
            {
                #region Arrange

                var validStartDateTime = new DateTime(2014, 1, 31);
                const int validMonthsBetweenOccurrences = 2;
                DateTime validEndDateTime = validStartDateTime.AddMonths(9);
                var validDayOfMonthMonthlyRecurrence = new DayOfMonthMonthlyRecurrence(validStartDateTime,
                    validMonthsBetweenOccurrences, validEndDateTime);

                var expectedRecurrenceSet = new List<DateTime>
                {
                    validStartDateTime, // 1/31/2014 (January)
                    validStartDateTime.AddMonths(2), // 3/31/2014 (March)
                    validStartDateTime.AddMonths(4), // 5/31/2014 (May)
                    validStartDateTime.AddMonths(6) // 7/31/2014 (July)
                    // no 9/31/2014 (September) because September only has 30 days so its skipped
                };

                #endregion

                #region Act

                IEnumerable<DateTime> recurrenceSet = validDayOfMonthMonthlyRecurrence.CalculateRecurrenceSet();

                #endregion

                #region Assert

                Assert.IsTrue(expectedRecurrenceSet.SequenceEqual(recurrenceSet));

                #endregion
            }
开发者ID:TonightWe,项目名称:TW.Recurrence,代码行数:33,代码来源:DayOfMonthMonthlyRecurrenceTests.cs

示例3: CalculatedRecurrenceSetPagingWorks

            public void CalculatedRecurrenceSetPagingWorks()
            {
                #region Arrange

                var validStartDateTime = new DateTime(2014, 1, 31);
                const int validMonthsBetweenOccurrences = 2;
                DateTime validEndDateTime = validStartDateTime.AddMonths(9);
                var validDayOfMonthMonthlyRecurrence = new DayOfMonthMonthlyRecurrence(validStartDateTime,
                    validMonthsBetweenOccurrences, validEndDateTime);

                var expectedRecurrenceSet = new List<DateTime>
                {
                    validStartDateTime.AddMonths(2), // 3/31/2014 (March)
                    validStartDateTime.AddMonths(4) // 5/31/2014 (May)
                };

                #endregion

                #region Act

                const int validSkip = 1;
                const int validTake = 2;
                IEnumerable<DateTime> recurrenceSet = validDayOfMonthMonthlyRecurrence.CalculateRecurrenceSet(
                    validSkip, validTake);

                #endregion

                #region Assert

                Assert.IsTrue(expectedRecurrenceSet.SequenceEqual(recurrenceSet));

                #endregion
            }
开发者ID:TonightWe,项目名称:TW.Recurrence,代码行数:33,代码来源:DayOfMonthMonthlyRecurrenceTests.cs

示例4: IsYellow

 public static bool IsYellow(DateTime inputDate)
 {
     var thisMonthStartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
     var legitimateStartDate = thisMonthStartDate.AddMonths(-2);
     var legitimateEndDate = thisMonthStartDate.AddMonths(-1);
     return inputDate >= legitimateStartDate && inputDate < legitimateEndDate;
 }
开发者ID:deepak2007in,项目名称:Sharepoint,代码行数:7,代码来源:ProjectColor.cs

示例5: Next

        public override DateTime Next(DateTime time, out bool changed)
        {
            changed = false;

            if (Values.Count < 1)
            {
                return time;
            }
            if (Type == CGtd.DATES_TYPE_EACH)
            {
                return time.AddMonths(Values[0]);
            }
            if (Type == CGtd.DATES_TYPE_WHEN)
            {
                int idx = time.Month;
                int tmp = NextValue(idx, changed);
                if (tmp > 0)
                {
                    return time.AddMonths(tmp);
                }
                if (tmp < 0)
                {
                    changed = true;
                    return time.AddYears(1).AddMonths(Values[0] - idx);
                }
            }
            return time;
        }
开发者ID:burstas,项目名称:rmps,代码行数:28,代码来源:Month.cs

示例6: NextFullMoon

 public static DateTime NextFullMoon(DateTime fromDate)
 {
     if (calcNext(fromDate.Year, fromDate.Month, fromDate.Day) == new DateTime())
         return calcNext(fromDate.AddMonths(1).Year, fromDate.AddMonths(1).Month, 1);
     else
         return calcNext(fromDate.Year, fromDate.Month, fromDate.Day);
 }
开发者ID:Winterstark,项目名称:Wallcreeper,代码行数:7,代码来源:classMoon.cs

示例7: GetCycleSummary

        public List<Tuple<string, string, decimal>> GetCycleSummary(int monthAgo)
        {
            DateTime cycleStart = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            cycleStart = cycleStart.AddMonths(-monthAgo);
            DateTime cycleEnd = cycleStart.AddMonths(1);

            using (ShowcaseDB db = new ShowcaseDB())
            {
                var l = (from e in db.Expenses
                         where e.TransactionDate >= cycleStart && e.TransactionDate < cycleEnd
                         group e by e.Category into grp
                         orderby grp.Key
                         select new { grp.Key, grp }).ToList();

                //var l2 = from cc in CategoryCharToName.Keys
                //		 join c in l on cc equals c.Key into g
                //		 from c in g.DefaultIfEmpty()
                //		 select Tuple.Create(cc, CategoryCharToName[cc], c != null ? c.grp.Sum(e => e.Amount) : 0);

                var ret = l.Select(g => Tuple.Create<string, string, decimal>(g.Key, CategoryCharToName[g.Key], g.grp.Sum(e => e.Amount))).ToList();

                if (ret.Count == 0) ret.Add(Tuple.Create("1", CategoryCharToName["1"], 0M));

                return ret;
            }
        }
开发者ID:rongzhu,项目名称:testgit,代码行数:26,代码来源:Reporter.cs

示例8: Index

        public ActionResult Index()
        {
            var startDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);
            using (var dbContext = new ReportingContext())
            {
                var buildSummary = GetLastBuildSummary(dbContext);
                var viewModel = new HomeViewModel
                {
                    Builds = buildSummary,
                    CoverageStat = new ModuleCoverageForABuild(),
                    Challenges = ComputeChallengesSummary(dbContext, startDate, startDate.AddMonths(1)),
                };

                var mainProjectName = ConfigurationManager.AppSettings["MainProjectName"];
                var lastBuild = !string.IsNullOrEmpty(mainProjectName) ? buildSummary.FirstOrDefault(i => i.ActualBuild.Definition == mainProjectName) : buildSummary.FirstOrDefault();
                if (lastBuild != null)
                {
                    var coverages = lastBuild.ActualBuild.CoverageCollection.OrderBy(i => (i.BlocksCovered * 100) / (i.BlocksNotCovered + i.BlocksCovered)).ToArray();
                    viewModel.CoverageStat.Modules = string.Join(", ", coverages.Select(i => i.Name.Replace(".dll", string.Empty).Replace(".exe", string.Empty)));
                    viewModel.CoverageStat.Coverages = string.Join(", ", coverages.Select(i => (i.BlocksCovered * 100) / (i.BlocksNotCovered + i.BlocksCovered)));
                }

                viewModel.ShootBoxBuilds = GetLastBuilds(dbContext, startDate, startDate.AddMonths(1)).ToArray();
                return View(viewModel);
            }
        }
开发者ID:L3Z4,项目名称:ContinuousReporting,代码行数:26,代码来源:HomeController.cs

示例9: DataBoundCalendarHeader

 public DataBoundCalendarHeader(DateTime VisibleDate)
 {
     _dataItem = new System.Collections.Generic.Dictionary<string, DateTime>();
     _prevMonth = VisibleDate.AddMonths(-1);
     _currMonth = VisibleDate;
     _nextMonth = VisibleDate.AddMonths(1);
 }
开发者ID:saiesh86,项目名称:TravelBlog,代码行数:7,代码来源:ItemTemplates.cs

示例10: Forcast

        /// <summary>
        /// Should forcast using 12 months data, falling back to 6 month if unavailable
        /// //ForcastSlope = _ForcastVals[0];
        //ForcastIntercept = _ForcastVals[1];
        //ForcastValue = _ForcastVals[2];
        //ForcastRangeUpperBount = _ForcastVals[3];
        /// </summary>
        /// <param name="SKUID"></param>
        private double[] Forcast(int SkuId, DateTime EndDate)
        {
            StatusMonContext db = new StatusMonContext();
            List<double> SalesData;
            double[] xdata;
            double[] ydata;
            DateTime EndDate12 = EndDate.AddMonths(-12);
            DateTime EndDate6 = EndDate.AddMonths(-6);
            int date = (EndDate.Date.Year * 12 + EndDate.Date.Month);
            //Test if 12 Month of Data Exists
            if (db.SalesOrderDetails.Where(o => o.SalesOrder.OrderDate <= EndDate12).Count() > 0)
            {
                SalesData = MonthlySalesD(SkuId, EndDate.AddMonths(-11), EndDate);
                xdata = new double[] { date - 11, date - 10, date - 9, date - 8, date - 7, date - 6, date - 5, date - 4, date - 3, date - 2, date - 1, date };
                //12 Months!
            }
            else if (db.SalesOrderDetails.Where(o => o.SalesOrder.OrderDate.Date <= EndDate6).Count() > 0) {
                //6 Months
                SalesData = MonthlySalesD(SkuId, EndDate.AddMonths(-5), EndDate);
                xdata = new double[] { date - 5, date - 4, date - 3, date - 2, date - 1, date }; //Actual Values are nominal
            }
            else
            {
                //Not enough Data to forcast accurately
                db.Dispose();
                return new double[] { 0, 0, 0, 0};
            }
            db.Dispose();
            ydata = SalesData.ToArray();

            return Linear.Forcast(date + 1, xdata, ydata);
        }
开发者ID:wildbillcat,项目名称:InventoryForcast,代码行数:40,代码来源:ReportController.cs

示例11: GetNextPaymentDate

        /// <summary>
        /// 根据当前还款时间和还款周期,计算下一个还款时间
        /// </summary>
        /// <param name="thisPaymentDate">当前还款时间</param>
        /// <param name="paymentCircle">还款周期</param>
        /// <returns>一个还款时间</returns>
        public static DateTime GetNextPaymentDate(DateTime thisPaymentDate, PaymentTermTypes paymentCircle)
        {
            DateTime nextPaymentDate = DateTime.MinValue;
            switch (paymentCircle)
            {
                case PaymentTermTypes.Daily:
                    nextPaymentDate = thisPaymentDate.AddDays(1);
                    break;
                case PaymentTermTypes.Weekly:
                    nextPaymentDate = thisPaymentDate.AddDays(7);
                    break;
                case PaymentTermTypes.DoubleWeekly:
                    nextPaymentDate = thisPaymentDate.AddDays(14);
                    break;
                case PaymentTermTypes.DoubleMonthly:
                    nextPaymentDate = thisPaymentDate.AddMonths(2);
                    break;
                case PaymentTermTypes.Quarterly:
                    nextPaymentDate = thisPaymentDate.AddMonths(3);
                    break;
                case PaymentTermTypes.SemiYearly:
                    nextPaymentDate = thisPaymentDate.AddMonths(6);
                    break;
                case PaymentTermTypes.Annual:
                    nextPaymentDate = thisPaymentDate.AddYears(1);
                    break;
                case PaymentTermTypes.Monthly:
                default:
                    nextPaymentDate = thisPaymentDate.AddMonths(1);
                    break;
            }

            //贷款还款日期的时间精度仅仅控制到日,不对时分秒控制
            return nextPaymentDate.Date;
        }
开发者ID:notinmood,项目名称:hiland,代码行数:41,代码来源:LoanHelper.cs

示例12: AddPeriodToDate

        public static DateTime AddPeriodToDate(DateTime utcDate, Periods period)
        {
            switch(period)
            {
                case Periods.FiveYears:
                    return utcDate.AddYears(5);
                case Periods.Forever:
                    return DateTime.MaxValue;
                case Periods.OneMonth:
                    return utcDate.AddMonths(1);
                case Periods.OneTime:
                    return utcDate;
                case Periods.OneWeek:
                    return utcDate.AddDays(7);
                case Periods.OneYear:
                    return utcDate.AddYears(1);
                case Periods.SixMonths:
                    return utcDate.AddMonths(6);
                case Periods.ThirtyDays:
                    return utcDate.AddDays(30);
                case Periods.ThreeMonths:
                    return utcDate.AddMonths(3);
                case Periods.TwoWeeks:
                    return utcDate.AddDays(14);
                case Periods.TwoYears:
                    return utcDate.AddYears(2);
                case Periods.Unknown:
                    return utcDate;
            }

            return utcDate;
        }
开发者ID:NightOwl888,项目名称:MerchantTribe,代码行数:32,代码来源:Service.cs

示例13: CreateWeatherData

		public List<MonthlyTemp> CreateWeatherData()
		{
			var time = new DateTime(2004, 1, 1);
			var result = new List<MonthlyTemp>();
			Random r = new Random();

			for (int i = 0; i < 5; i++)
			{
				for (int a = 0; a < 3; a++)
				{
					result.Add(new MonthlyTemp(time, r.Next(0, 10)));
					time = time.AddMonths(1);
				}
				for (int a = 0; a < 3; a++)
				{
					result.Add(new MonthlyTemp(time, r.Next(10, 20)));
					time = time.AddMonths(1);
				}
				for (int a = 0; a < 3; a++)
				{
					result.Add(new MonthlyTemp(time, r.Next(20, 30)));
					time = time.AddMonths(1);
				}
				for (int a = 0; a < 3; a++)
				{
					result.Add(new MonthlyTemp(time, r.Next(10, 20)));
					time = time.AddMonths(1);
				}
			}
			return result;
		}
开发者ID:JoelWeber,项目名称:xaml-sdk,代码行数:31,代码来源:MainPage.xaml.cs

示例14: NextMonth

        public JsonResult NextMonth(int no, int locationId)
        {
            today = today.AddDays(no);

            GetDate();
            GetMonth();
            period = string.Format("{0}{1}", today.Year, bulan);
            var previousMonth = string.Format("{0}{1}", today.AddMonths(-1).Year, ConvertMonth(today.AddMonths(-1)));
            var twoBeforeMonth = string.Format("{0}{1}", today.AddMonths(-2).Year, ConvertMonth(today.AddMonths(-2)));
            IList<TenantSubterminalMonthlySales> monthlySales = subTerminalRepo.FindTenantSubTerminalMonthlySaleByPeriod(period, locationId);
            IList<TenantSubterminalMonthlySales> monthlyPreviousSales = subTerminalRepo.FindTenantSubTerminalMonthlySaleByPeriod(previousMonth, locationId);
            IList<TenantSubterminalMonthlySales> monthlyTwoBeforeSales = subTerminalRepo.FindTenantSubTerminalMonthlySaleByPeriod(twoBeforeMonth, locationId);
            SalesAmountMonth salesAmount = new SalesAmountMonth()
            {
                CompanyName = monthlySales[0].CompanyName,
                LocationId = locationId,
                TotalSaleIDRCurrentMonth = subTerminalRepo.TotalTenanSubTerminalSalePerMonth(monthlySales).ToString("N"),
                TotalSaleIDROneMonthBefore = monthlyPreviousSales.Sum<TenantSubterminalMonthlySales>(y => y.MonthlyTotalSalePerTenan).ToString("N"),
                TotalSaleIDRTwoMonthBefore = monthlyTwoBeforeSales.Sum<TenantSubterminalMonthlySales>(y => y.MonthlyTotalSalePerTenan).ToString("N"),
                Transactiondate = today.ToString("MMMM yyyy"),
                OneMonthBefore = today.AddMonths(-1).ToString("MMMM yyyy"),
                TwoMonthBefore = today.AddMonths(-2).ToString("MMMM yyyy"),
                TotalSaleUSDCurrentMonth = monthlySales.Sum<TenantSubterminalMonthlySales>(y => y.MonthlyTotalSalesPerTenantInUSD).ToString("N"),
                TotalSaleUSDOneMonthBefore = monthlyPreviousSales.Sum<TenantSubterminalMonthlySales>(y => y.MonthlyTotalSalesPerTenantInUSD).ToString("N"),
                TotalSaleUSDTwoMonthBefore = monthlyTwoBeforeSales.Sum<TenantSubterminalMonthlySales>(y => y.MonthlyTotalSalesPerTenantInUSD).ToString("N"),

            };

            return Json(salesAmount, JsonRequestBehavior.AllowGet);
        }
开发者ID:BonaStoco,项目名称:AP2,代码行数:30,代码来源:SubTerminalReportSaleController.cs

示例15: IncrementDate

        public static DateTime IncrementDate(this TimePeriod period, DateTime date, int amount)
        {
            switch (period) {
                case TimePeriod.Millisecond:
                    return date.AddMilliseconds(amount);
                case TimePeriod.Second:
                    return date.AddSeconds(amount);
                case TimePeriod.Minute:
                    return date.AddMinutes(amount);
                case TimePeriod.Hour:
                    return date.AddHours(amount);
                case TimePeriod.Day:
                    return date.AddDays(amount);
                case TimePeriod.Month:
                    return date.AddMonths(amount);
                case TimePeriod.Quarter:
                    return date.AddMonths(amount * 3);
                case TimePeriod.Half:
                    return date.AddMonths(amount * 6);
                case TimePeriod.Year:
                    return date.AddYears(amount);

                default:
                    throw new Exception("Unknown period: " + period.ToString());

            }
        }
开发者ID:GrowingData,项目名称:Mung,代码行数:27,代码来源:TimePeriod.cs


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