當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。