JapaneseCalendar.AddMonths(DateTime, Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
public:
override DateTime AddMonths(DateTime time, int months);
public override DateTime AddMonths(DateTime time, int months);
override this.AddMonths : DateTime * int -> DateTime
abstract member AddMonths : DateTime * int -> DateTime
override this.AddMonths : DateTime * int -> DateTime
Public Overrides Function AddMonths (time As DateTime, months As Integer) As DateTime
매개 변수
- months
- Int32
추가할 월 수입니다.
반품
DateTime 지정된 개월 수를 지정된 월에 추가한 DateTime결과입니다.
예외
결과는 DateTime 지원되는 범위를 벗어났습니다.
예제
다음 코드 예제에서는 일본 달력을 기준으로 여러 DateTime 구성 요소의 값을 표시합니다.
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월)이고, 결과 날짜는 시가쓰의 마지막 날인 30일입니다.
음수이면 months 결과 DateTime 값이 지정된 DateTime것보다 깁니다.
반환 Kind 된 값의 속성은 DateTime 항상 같습니다DateTimeKind.Unspecified. 다음 예제와 Kind 같이 메서드를 time 호출 DateTime.SpecifyKind 하여 매개 변수의 속성을 유지할 수 있습니다.
returnTime = DateTime.SpecifyKind(cal.AddMonths(time, months), time.Kind);
returnTime = DateTime.SpecifyKind(cal.AddMonths(time, months), time.Kind)