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


C# DateTime.AddYears方法代码示例

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


在下文中一共展示了DateTime.AddYears方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CanAddYearsAcrossDstTransition

        public void CanAddYearsAcrossDstTransition()
        {
            var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dt = new DateTime(2014, 3, 9, 0, 0, 0);
            var result = dt.AddYears(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

示例3: WithAge

 public MemberBuilder WithAge(int age, DateTime now)
 {
     _dob = now.AddYears(-age);
     return this;
 }
开发者ID:robdmoore,项目名称:TestWestTestDataSustainabilityPresentation,代码行数:5,代码来源:02_testdatabuilder.cs

示例4: AddYears

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

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

示例6: FormsAuthenticationTicket

		public FormsAuthenticationTicket (string name, bool isPersistent, int timeout)
		{
			this.version = 1;
			this.name = name;
			this.issue_date = DateTime.Now;
			this.persistent = isPersistent;
			if (persistent)
				expiration = issue_date.AddYears (50);
			else
				expiration = issue_date.AddMinutes ((double) timeout);

			this.user_data = "";
			this.cookie_path = "/";
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:FormsAuthenticationTicket.cs

示例7: AddYears

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

示例8: WA18YearOld

 public static Member WA18YearOld(DateTime now)
 {
     return new Member("18-Year-Old-in-WA", State.Wa, now.AddYears(-18));
 }
开发者ID:robdmoore,项目名称:TestWestTestDataSustainabilityPresentation,代码行数:4,代码来源:01_objectmother.cs

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