JapaneseCalendar.AddMonths(DateTime, Int32) 메서드

정의

지정된 DateTime에서 지정된 월 수만큼 경과한 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입니다.

months
Int32

더할 월 수입니다.

반환

지정된 DateTime에 지정된 월 수를 더한 결과로 만들어지는 DateTime입니다.

예외

결과 DateTime이 지원되는 범위 밖에 있는 경우

months가 -120000보다 작습니다.

또는

months가 120000보다 큽니다.

예제

다음 코드 예제에서는 일본어 달력의 측면에서 의 여러 구성 요소 DateTime 값을 표시 합니다.

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 JapaneseCalendar.
   JapaneseCalendar^ myCal = gcnew JapaneseCalendar;
   
   // Displays the values of the DateTime.
   Console::WriteLine( "April 3, 2002 of the Gregorian calendar equals the following in the Japanese 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 Japanese calendar:
   Era:        4
   Year:       14
   Month:      4
   DayOfYear:  93
   DayOfMonth: 3
   DayOfWeek:  Wednesday

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

*/
using System;
using System.Globalization;

public class SamplesJapaneseCalendar  {

   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 JapaneseCalendar.
      JapaneseCalendar myCal = new JapaneseCalendar();

      // Displays the values of the DateTime.
      Console.WriteLine( "April 3, 2002 of the Gregorian calendar equals the following in the Japanese 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 Japanese calendar:
   Era:        4
   Year:       14
   Month:      4
   DayOfYear:  93
   DayOfMonth: 3
   DayOfWeek:  Wednesday

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

*/
Imports System.Globalization


Public Class SamplesJapaneseCalendar   

   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 JapaneseCalendar.
      Dim myCal As New JapaneseCalendar()

      ' Displays the values of the DateTime.
      Console.WriteLine("April 3, 2002 of the Gregorian calendar equals the following in the Japanese 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

   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

End Class


'This code produces the following output.
'
'April 3, 2002 of the Gregorian calendar equals the following in the Japanese calendar:
'   Era:        4
'   Year:       14
'   Month:      4
'   DayOfYear:  93
'   DayOfMonth: 3
'   DayOfWeek:  Wednesday
'
'After adding two years and ten months:
'   Era:        4
'   Year:       17
'   Month:      2
'   DayOfYear:  34
'   DayOfMonth: 3
'   DayOfWeek:  Thursday

설명

결과 날짜가 결과 연도의 결과 월에서 유효한 날이 아닌 경우 결과 DateTime 날짜의 일 부분이 영향을 받습니다. 결과 연도의 결과 월에서 마지막 유효한 날로 변경됩니다. 결과 월이 지정된 연도를 벗어나면 결과 DateTime 의 연도 부분이 영향을 받습니다 DateTime. 결과 연도가 지정된 의 시대를 벗어나면 결과 DateTime 의 시대 부분이 영향을 받습니다 DateTime. 결과 DateTime 의 하루 중 시간 부분은 지정된 와 동일하게 유지됩니다 DateTime.

예를 들어 지정된 월이 31일인 Juugatsu(10월)이면 지정된 날짜는 해당 월의 31일이고 months , 결과 연도는 지정된 연도보다 1개 이상, 결과 월은 시가쓰(4월)이고, 결과일은 시가쓰(4월)의 마지막 날인 30일입니다.

가 음수이면 months 결과는 DateTime 지정된 DateTime보다 이전입니다.

반환 DateTime 된 값의 속성은 Kind 항상 와 같습니다DateTimeKind.Unspecified. 다음 예제와 같이 메서드를 Kindtime 호출 DateTime.SpecifyKind 하여 매개 변수의 속성을 유지할 수 있습니다.

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

적용 대상

추가 정보