HebrewCalendar.AddYears(DateTime, Int32) 메서드

정의

지정된 DateTime에서 지정된 연도 수만큼 경과한 DateTime을 반환합니다.

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

매개 변수

time
DateTime

years를 더할 DateTime입니다.

years
Int32

더할 연도 수입니다.

반환

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

예외

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

예제

다음 코드 예제에서는 히브리어 달력의 측면에서 의 여러 구성 요소 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 HebrewCalendar.
   HebrewCalendar^ myCal = gcnew HebrewCalendar;
   
   // Displays the values of the DateTime.
   Console::WriteLine( "April 3, 2002 of the Gregorian calendar equals the following in the Hebrew 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 Hebrew calendar:
   Era:        1
   Year:       5762
   Month:      7
   DayOfYear:  198
   DayOfMonth: 21
   DayOfWeek:  Wednesday

After adding two years and ten months:
   Era:        1
   Year:       5765
   Month:      5
   DayOfYear:  138
   DayOfMonth: 21
   DayOfWeek:  Monday

*/
using System;
using System.Globalization;

public class SamplesHebrewCalendar  {

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

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

After adding two years and ten months:
   Era:        1
   Year:       5765
   Month:      5
   DayOfYear:  138
   DayOfMonth: 21
   DayOfWeek:  Monday

*/
Imports System.Globalization


Public Class SamplesHebrewCalendar   

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

      ' Displays the values of the DateTime.
      Console.WriteLine("April 3, 2002 of the Gregorian calendar equals the following in the Hebrew 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 Hebrew calendar:
'   Era:        1
'   Year:       5762
'   Month:      7
'   DayOfYear:  198
'   DayOfMonth: 21
'   DayOfWeek:  Wednesday
'
'After adding two years and ten months:
'   Era:        1
'   Year:       5765
'   Month:      5
'   DayOfYear:  138
'   DayOfMonth: 21
'   DayOfWeek:  Monday

설명

이 클래스 구현 HebrewCalendar 은 히브리어 5343년에서 5999년(그레고리력에서 1583년에서 2239년)만 인식합니다.

결과 날짜가 결과 연도의 결과 월에서 유효한 날이 아닌 경우 결과 DateTime 날짜의 일 부분이 영향을 받습니다. 결과 연도의 결과 월에서 마지막 유효한 날로 변경됩니다. 예를 들어 Cheshvan은 유대인 휴일의 배치에 따라 29일 또는 30일을 가질 수 있습니다. Cheshvan이 현재 연도에 30일, 다음 해에 29일이 있다고 가정합니다. 지정된 날짜가 현재 연도의 Cheshvan 30일이고 값 years 이 1인 경우 결과 날짜는 다음 해의 Cheshvan 29일이 됩니다.

결과 월이 결과 연도의 유효한 월이 아닌 경우 결과 DateTime 월 부분이 영향을 받습니다. 결과 연도의 마지막 유효 월로 변경됩니다. 예를 들어 매개 변수의 time 월이 윤년의 13번째 달이고 값 years 이 1인 경우 결과 DateTime 월은 다음 해의 12번째 달이며 이는 비윤년입니다. 월 부분이 변경되지 않더라도 다른 월을 참조할 수 있습니다. 예를 들어 Adar Beit는 윤년의 7번째 달이지만 닛산은 일반적인 연도의 7번째 달입니다.

이 구현은 현재 시대만 지원합니다. 따라서 ArgumentException 결과 연도가 지정된 의 시대를 벗어나면 이 throw됩니다 DateTime.

결과 DateTime 의 하루 중 시간 부분은 지정된 와 동일하게 유지됩니다 DateTime.

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

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

returnTime = DateTime.SpecifyKind(cal.AddYears(time, years), time.Kind);
returnTime = DateTime.SpecifyKind(cal.AddYears(time, years), time.Kind)

적용 대상

추가 정보