EastAsianLunisolarCalendar.AddMonths(DateTime, Int32) 方法

定義

計算與指定日期相差指定月數的日期。

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

要將 months 加入的 DateTime

months
Int32

要新增的月數。

傳回

DateTime,將所指定月數加入至 time 參數所產生。

例外狀況

結果不在 DateTime 支援的範圍內。

months 小於 -120000 或大於 120000。

-或-

time 小於 MinSupportedDateTime 或大於 MaxSupportedDateTime

備註

如果產生的日期不是結果年份結果月份的有效日期,則產生的 DateTime 日期部分會受到影響。 在此情況下,日期部分會變更為結果年份結果月份的最後一個有效日。 如果產生的月份超出指定的 DateTime年份,則產生的DateTime年份部分會受到影響。 此實作僅支援目前的紀元。 因此, ArgumentException 如果產生的年份超出指定的 DateTime紀元,則會擲回 。 結果 DateTime 的當日時間部分會維持與指定的 DateTime相同。

例如,如果指定的月份為 10 月,其具有 31 天,則指定的日期是該月份的第 30 天,而 參數的值 months 是 6,產生的年份是指定年份的一個以上,產生的月份是 4 月,而產生的日期是 4 月的第二天,也就是 4 月的最後一天。

如果參數的值 months 是負數,則產生的 DateTime 值早於指定的 DateTime

KindDateTime 值的 屬性一律等於 DateTimeKind.Unspecified。 您可以呼叫 DateTime.SpecifyKind 方法來保留 Kind 參數的 time 屬性,如下列範例所示。

returnTime = DateTime.SpecifyKind(cal.AddMonths(time, months), time.Kind);
returnTime = DateTime.SpecifyKind(cal.AddMonths(time, months), time.Kind)

適用於