EastAsianLunisolarCalendar.AddMonths(DateTime, Int32) 方法

定义

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

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

参数

time
DateTime

DateTime,将向其添加 monthsThe DateTime to which to add months.

months
Int32

要添加的月数。The number of months to add.

返回

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

异常

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

months 小于-120000 或大于 120000。months is less than -120000 or greater than 120000.

-or- time 小于 MinSupportedDateTime 或大于 MaxSupportedDateTimetime is less than MinSupportedDateTime or greater than MaxSupportedDateTime.

注解

如果生成的日期不是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 year part of the resulting DateTime is affected if the resulting month is outside the year of 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.

例如, 如果指定的月份是10月 (包含31天), 则指定的日期是该月的第30天, 而months参数的值为 6, 则生成的年份比指定年份多一, 结果月份是四月,结果 day 是 thirtieth day, 这是四月的最后一天。For example, if the specified month is October, which has 31 days, the specified day is the thirty-first day of that month, and the value of the months parameter is 6, the resulting year is one more than the specified year, the resulting month is April, and the resulting day is the thirtieth day, which is the last day in April.

如果months参数的值为负, 则生成DateTime的值早于指定DateTime的。If the value of the months parameter 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.AddMonths(time, months), time.Kind);
returnTime = DateTime.SpecifyKind(cal.AddMonths(time, months), time.Kind)

适用于