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

一个新的 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 保持与指定的相同 DateTimeThe month part of the resulting DateTime remains the same as the specified DateTime. 此实现仅支持当前纪元。This implementation supports only the current era. 因此, ArgumentException 如果生成的年份超出指定的纪元,则会引发 DateTimeTherefore, ArgumentException is thrown if the resulting year is outside the era of the specified DateTime. 生成的的时间部分与 DateTime 指定的相同 DateTimeThe 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 早于指定的 DateTimeIf years is negative, the resulting DateTime is earlier than the specified DateTime.

Kind返回的值的属性 DateTime 始终相等 DateTimeKind.UnspecifiedThe 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)

适用于