KoreanCalendar.AddMonths(DateTime, Int32) KoreanCalendar.AddMonths(DateTime, Int32) KoreanCalendar.AddMonths(DateTime, Int32) KoreanCalendar.AddMonths(DateTime, Int32) Method

정의

지정된 DateTime에서 지정된 월 수만큼 경과한 DateTime을 반환합니다.Returns a DateTime that is the specified number of months away from the specified DateTime.

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 DateTime DateTime

월을 더할 DateTime입니다.The DateTime to which to add months.

months
Int32 Int32 Int32 Int32

더할 월 수입니다.The number of months to add.

반환

지정된 DateTime에 지정된 월 수를 더한 결과로 만들어지는 DateTime입니다.The DateTime that results from adding the specified number of months to the specified DateTime.

예외

months가 -120000보다 작습니다.months is less than -120000.

또는-or- months가 120000보다 큽니다.months is greater than 120000.

예제

여러 구성 요소 값을 표시 하는 다음 코드 예제는 DateTime 한국식 달력을 기준으로 합니다.The following code example displays the values of several components of a DateTime in terms of the Korean calendar.

using namespace System;
using namespace System::Globalization;
void DisplayValues( Calendar^ myCal, DateTime myDT )
{
   Console::WriteLine( "   Era:        {0}", myCal->GetEra( myDT ) );
   Console::WriteLine( "   Year:       {0}", myCal->GetYear( myDT ) );
   Console::WriteLine( "   Month:      {0}", myCal->GetMonth( myDT ) );
   Console::WriteLine( "   DayOfYear:  {0}", myCal->GetDayOfYear( myDT ) );
   Console::WriteLine( "   DayOfMonth: {0}", myCal->GetDayOfMonth( myDT ) );
   Console::WriteLine( "   DayOfWeek:  {0}", myCal->GetDayOfWeek( myDT ) );
   Console::WriteLine();
}

int main()
{
   
   // Sets a DateTime to April 3, 2002 of the Gregorian calendar.
   DateTime myDT = DateTime(2002,4,3,gcnew GregorianCalendar);
   
   // Creates an instance of the KoreanCalendar.
   KoreanCalendar^ myCal = gcnew KoreanCalendar;
   
   // Displays the values of the DateTime.
   Console::WriteLine( "April 3, 2002 of the Gregorian calendar equals the following in the Korean calendar:" );
   DisplayValues( myCal, myDT );
   
   // Adds two years and ten months.
   myDT = myCal->AddYears( myDT, 2 );
   myDT = myCal->AddMonths( myDT, 10 );
   
   // Displays the values of the DateTime.
   Console::WriteLine( "After adding two years and ten months:" );
   DisplayValues( myCal, myDT );
}

/*
This code produces the following output.

April 3, 2002 of the Gregorian calendar equals the following in the Korean calendar:
   Era:        1
   Year:       4335
   Month:      4
   DayOfYear:  93
   DayOfMonth: 3
   DayOfWeek:  Wednesday

After adding two years and ten months:
   Era:        1
   Year:       4338
   Month:      2
   DayOfYear:  34
   DayOfMonth: 3
   DayOfWeek:  Thursday

*/
using System;
using System.Globalization;


public class SamplesKoreanCalendar  {

   public static void Main()  {

      // Sets a DateTime to April 3, 2002 of the Gregorian calendar.
      DateTime myDT = new DateTime( 2002, 4, 3, new GregorianCalendar() );

      // Creates an instance of the KoreanCalendar.
      KoreanCalendar myCal = new KoreanCalendar();

      // Displays the values of the DateTime.
      Console.WriteLine( "April 3, 2002 of the Gregorian calendar equals the following in the Korean calendar:" );
      DisplayValues( myCal, myDT );

      // Adds two years and ten months.
      myDT = myCal.AddYears( myDT, 2 );
      myDT = myCal.AddMonths( myDT, 10 );

      // Displays the values of the DateTime.
      Console.WriteLine( "After adding two years and ten months:" );
      DisplayValues( myCal, myDT );

   }

   public static void DisplayValues( Calendar myCal, DateTime myDT )  {
      Console.WriteLine( "   Era:        {0}", myCal.GetEra( myDT ) );
      Console.WriteLine( "   Year:       {0}", myCal.GetYear( myDT ) );
      Console.WriteLine( "   Month:      {0}", myCal.GetMonth( myDT ) );
      Console.WriteLine( "   DayOfYear:  {0}", myCal.GetDayOfYear( myDT ) );
      Console.WriteLine( "   DayOfMonth: {0}", myCal.GetDayOfMonth( myDT ) );
      Console.WriteLine( "   DayOfWeek:  {0}", myCal.GetDayOfWeek( myDT ) );
      Console.WriteLine();
   }

}

/*
This code produces the following output.

April 3, 2002 of the Gregorian calendar equals the following in the Korean calendar:
   Era:        1
   Year:       4335
   Month:      4
   DayOfYear:  93
   DayOfMonth: 3
   DayOfWeek:  Wednesday

After adding two years and ten months:
   Era:        1
   Year:       4338
   Month:      2
   DayOfYear:  34
   DayOfMonth: 3
   DayOfWeek:  Thursday

*/
Imports System
Imports System.Globalization


Public Class SamplesKoreanCalendar   

   Public Shared Sub Main()

      ' Sets a DateTime to April 3, 2002 of the Gregorian calendar.
      Dim myDT As New DateTime(2002, 4, 3, New GregorianCalendar())

      ' Creates an instance of the KoreanCalendar.
      Dim myCal As New KoreanCalendar()

      ' Displays the values of the DateTime.
      Console.WriteLine("April 3, 2002 of the Gregorian calendar equals the following in the Korean calendar:")
      DisplayValues(myCal, myDT)

      ' Adds two years and ten months.
      myDT = myCal.AddYears(myDT, 2)
      myDT = myCal.AddMonths(myDT, 10)

      ' Displays the values of the DateTime.
      Console.WriteLine("After adding two years and ten months:")
      DisplayValues(myCal, myDT)

   End Sub 'Main

   Public Shared Sub DisplayValues(myCal As Calendar, myDT As DateTime)
      Console.WriteLine("   Era:        {0}", myCal.GetEra(myDT))
      Console.WriteLine("   Year:       {0}", myCal.GetYear(myDT))
      Console.WriteLine("   Month:      {0}", myCal.GetMonth(myDT))
      Console.WriteLine("   DayOfYear:  {0}", myCal.GetDayOfYear(myDT))
      Console.WriteLine("   DayOfMonth: {0}", myCal.GetDayOfMonth(myDT))
      Console.WriteLine("   DayOfWeek:  {0}", myCal.GetDayOfWeek(myDT))
      Console.WriteLine()
   End Sub 'DisplayValues

End Class 'SamplesKoreanCalendar 


'This code produces the following output.

'

'April 3, 2002 of the Gregorian calendar equals the following in the Korean calendar:

'   Era:        1

'   Year:       4335

'   Month:      4

'   DayOfYear:  93

'   DayOfMonth: 3

'   DayOfWeek:  Wednesday

'

'After adding two years and ten months:

'   Era:        1

'   Year:       4338

'   Month:      2

'   DayOfYear:  34

'   DayOfMonth: 3

'   DayOfWeek:  Thursday


설명

결과의 일 부분 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. 결과 결과 연도 월의 마지막 유효 날짜로 변경 됩니다.It 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 결과인 연도 지정 된 연대를 벗어나는 경우 throw 됩니다 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 일에는 지정 된 일 경우의 값과 그 달의 31 번째 날은 months 매개 변수가 6를 하나의 결과 연도 4 월 및 결과 da 결과 월의이 지정 된 연도의 더 y가 4 월의 마지막 날에는 30 일입니다.For example, if the specified month is October, which has 31 days, the specified day is the 31st 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 30th 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)

적용 대상

추가 정보