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
参数
- 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.
例外
months 小于-120000 或大于 120000。months is less than -120000 or greater than 120000.
或-or-
time 小于 MinSupportedDateTime 或大于 MaxSupportedDateTime。time 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天),则指定的日期是该月的第几天,而参数的值 months 为6,则生成的年份比指定的年份多一,生成的月份是4月,而结果日是 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.
Kind返回的值的属性 DateTime 始终相等 DateTimeKind.Unspecified 。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)