本文整理汇总了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;
}
示例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);
}
示例3: WithAge
public MemberBuilder WithAge(int age, DateTime now)
{
_dob = now.AddYears(-age);
return this;
}
示例4: AddYears
public void AddYears(DateTime time, int years)
{
Assert.Equal(time.AddYears(years), new ThaiBuddhistCalendar().AddYears(time, years));
}
示例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();
}
示例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 = "/";
}
示例7: AddYears
public void AddYears(DateTime time, int years)
{
Assert.Equal(time.AddYears(years), new KoreanCalendar().AddYears(time, years));
}
示例8: WA18YearOld
public static Member WA18YearOld(DateTime now)
{
return new Member("18-Year-Old-in-WA", State.Wa, now.AddYears(-18));
}
示例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();
}