EastAsianLunisolarCalendar.AddYears(DateTime, Int32) 方法

定义

计算与指定日期相距指定年数的日期。Calculates the date that is the specified number of years away from the specified date.

public:
 override DateTime AddYears(DateTime time, int years);
public override DateTime AddYears (DateTime time, int years);
override this.AddYears : DateTime * int -> DateTime
Public Overrides Function AddYears (time As DateTime, years As Integer) As DateTime

参数

time
DateTime

DateTime,将向其添加 yearsThe DateTime to which to add years.

years
Int32

要添加的年数。The number of years to add.

返回

一个新的 DateTime,通过在 time 参数中添加指定的年数得到。A new DateTime that results from adding the specified number of years to the time parameter.

异常

结果超出了 DateTime 支持的范围。The result is outside the supported range of a DateTime.

注解

如果生成的日期不是DateTime结果年份的结果月份中的有效日期, 则结果中的日部分会受到影响。The day part of the resulting DateTime is affected if the resulting day is not a valid day in the resulting month of the resulting year. 在这种情况下, 日期部分将更改为生成的年份中的最后一个有效日。In this case, the day part is changed to the last valid day in the resulting month of the resulting year. 所得DateTime的月份部分将保持与指定DateTime的相同。The month part of the resulting DateTime remains the same as the specified DateTime. 此实现仅支持当前纪元。This implementation supports only the current era. 因此, ArgumentException如果生成的年份超出指定DateTime的纪元, 则会引发。Therefore, ArgumentException is thrown if the resulting year is outside the era of the specified DateTime. 生成DateTime的的时间部分与指定DateTime的相同。The time-of-day part of the resulting DateTime remains the same as the specified DateTime.

例如, 2 月有28天, 在闰年有29天时除外。For example, February has 28 days, except during leap years when it has 29 days. 如果指定的日期是一年2月20日, 并且该years参数的值为 1, 则生成的日期将是下一年2月20日。If the specified date is the twenty-ninth day of February in a leap year and the value of the years parameter is 1, the resulting date will be the twenty-eighth day of February in the following year.

如果years为负, 则生成DateTime的早于指定DateTime的。If years is negative, the resulting DateTime is earlier than the specified DateTime.

DateTimeKind.Unspecified返回Kind 的值的DateTime属性始终相等。The Kind property of the returned DateTime value always equals DateTimeKind.Unspecified. 可以通过调用Kind time 方法来保留参数的属性,如下面的DateTime.SpecifyKind示例所示。You can preserve the Kind property of the time parameter by calling the DateTime.SpecifyKind method, as the following example shows.

returnTime = DateTime.SpecifyKind(cal.AddYears(time, years), time.Kind);
returnTime = DateTime.SpecifyKind(cal.AddYears(time, years), time.Kind)

适用于