本文整理汇总了C#中System.Globalization.GregorianCalendar.AddYears方法的典型用法代码示例。如果您正苦于以下问题:C# GregorianCalendar.AddYears方法的具体用法?C# GregorianCalendar.AddYears怎么用?C# GregorianCalendar.AddYears使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.AddYears方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest5
public void PosTest5()
{
DateTime initialTime;
int years;
DateTime resultingTime;
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
years = 13;
initialTime = myCalendar.ToDateTime(2000, 2, 29, 10, 30, 24, 0);
resultingTime = myCalendar.AddYears(initialTime, years);
VerifyAddyearsResult(myCalendar, initialTime, resultingTime, years);
}
示例2: PosTest3
public void PosTest3()
{
DateTime initialTime;
int years;
DateTime resultingTime;
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
years = -99;
initialTime = myCalendar.MaxSupportedDateTime;
resultingTime = myCalendar.AddYears(initialTime, years);
VerifyAddyearsResult(myCalendar, initialTime, resultingTime, years);
}
示例3: PosTest1
public void PosTest1()
{
DateTime initialTime;
int years;
DateTime resultingTime;
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
years = 0;
initialTime = DateTime.Now;
resultingTime = myCalendar.AddYears(initialTime, years);
Assert.Equal(initialTime, resultingTime);
}
示例4: AddYears
/// <summary>
/// Inherited code: Requires comment.
/// </summary>
/// <param name="time">Inherited code: Requires comment 1.</param>
/// <param name="years">Inherited code: Requires comment 2.</param>
/// <returns>Inherited code: Requires comment 3.</returns>
public static DateTime? AddYears(DateTime time, int years)
{
System.Globalization.Calendar cal = new GregorianCalendar();
try
{
return cal.AddYears(time, years);
}
catch (ArgumentException)
{
return null;
}
}
示例5: PosTest4
public void PosTest4()
{
DateTime initialTime;
int years;
DateTime resultingTime;
System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
years = 1;
long maxTimeInTicks = myCalendar.MaxSupportedDateTime.Ticks;
long minTimeInTikcs = myCalendar.MinSupportedDateTime.Ticks;
initialTime = new DateTime(_generator.GetInt64(-55) % maxTimeInTicks);
resultingTime = myCalendar.AddYears(initialTime, years);
VerifyAddyearsResult(myCalendar, initialTime, resultingTime, years);
}
示例6: AddYearOnLeapYear
public void AddYearOnLeapYear ()
{
GregorianCalendar c = new GregorianCalendar ();
DateTime d = new DateTime (2004, 2, 29);
DateTime prev = c.AddYears (d, -1);
Assert.AreEqual (2, prev.Month, "prev");
DateTime next = c.AddYears (d, 1);
Assert.AreEqual (2, next.Month, "next");
}
示例7: NegTest1
public void NegTest1()
{
DateTime time;
int years;
System.Globalization.Calendar myCalendar;
time = DateTime.Now;
years = 9999;
myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
myCalendar.AddYears(time, years);
});
}
示例8: ProcessPageUpKey
private void ProcessPageUpKey()
{
System.Globalization.Calendar _cal = new GregorianCalendar();
if (this.DisplayMode == CalendarMode.Month)
{
DateTime selectedDate = _cal.AddMonths(this.SelectedDate.GetValueOrDefault(DateTime.Today), -1);
if (IsValidDate(this,selectedDate))
{
OnDayClick(selectedDate);
}
}
else
{
Debug.Assert(this.DisplayMode == CalendarMode.Year);
DateTime selectedMonth = _cal.AddYears(this._selectedMonth, -1);
OnSelectedMonthChanged(selectedMonth);
}
}