GregorianCalendar.GetDaysInMonth(Int32, Int32, Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した年の指定した年の指定した月の日数を返します。
public:
override int GetDaysInMonth(int year, int month, int era);
public override int GetDaysInMonth(int year, int month, int era);
override this.GetDaysInMonth : int * int * int -> int
abstract member GetDaysInMonth : int * int * int -> int
override this.GetDaysInMonth : int * int * int -> int
Public Overrides Function GetDaysInMonth (year As Integer, month As Integer, era As Integer) As Integer
パラメーター
- year
- Int32
年を表す整数。
- month
- Int32
月を表す 1 ~ 12 の整数。
- era
- Int32
時代 (年号) を表す整数。
返品
指定した時代 (年号) の指定した年の指定した月の日数。
例外
era がカレンダーでサポートされている範囲外です。
-または-
year がカレンダーでサポートされている範囲外です。
-または-
month がカレンダーでサポートされている範囲外です。
例
次のコード例では、各時代 (年号) の 5 年ごとに 2 か月目の GetDaysInMonth を呼び出します。
using System;
using System.Globalization;
public class SamplesGregorianCalendar {
public static void Main() {
// Creates and initializes a GregorianCalendar.
GregorianCalendar myCal = new GregorianCalendar();
// Displays the header.
Console.Write( "YEAR\t" );
for ( int y = 2001; y <= 2005; y++ )
Console.Write( "\t{0}", y );
Console.WriteLine();
// Displays the value of the CurrentEra property.
Console.Write( "CurrentEra:" );
for ( int y = 2001; y <= 2005; y++ )
Console.Write( "\t{0}", myCal.GetDaysInMonth( y, 2, GregorianCalendar.CurrentEra ) );
Console.WriteLine();
// Displays the values in the Eras property.
for ( int i = 0; i < myCal.Eras.Length; i++ ) {
Console.Write( "Era {0}:\t", myCal.Eras[i] );
for ( int y = 2001; y <= 2005; y++ )
Console.Write( "\t{0}", myCal.GetDaysInMonth( y, 2, myCal.Eras[i] ) );
Console.WriteLine();
}
}
}
/*
This code produces the following output.
YEAR 2001 2002 2003 2004 2005
CurrentEra: 28 28 28 29 28
Era 1: 28 28 28 29 28
*/
Imports System.Globalization
Public Class SamplesGregorianCalendar
Public Shared Sub Main()
' Creates and initializes a GregorianCalendar.
Dim myCal As New GregorianCalendar()
' Displays the header.
Console.Write("YEAR" + ControlChars.Tab)
Dim y As Integer
For y = 2001 To 2005
Console.Write(ControlChars.Tab + "{0}", y)
Next y
Console.WriteLine()
' Displays the value of the CurrentEra property.
Console.Write("CurrentEra:")
For y = 2001 To 2005
Console.Write(ControlChars.Tab + "{0}", myCal.GetDaysInMonth(y, 2, GregorianCalendar.CurrentEra))
Next y
Console.WriteLine()
' Displays the values in the Eras property.
Dim i As Integer
For i = 0 To myCal.Eras.Length - 1
Console.Write("Era {0}:" + ControlChars.Tab, myCal.Eras(i))
For y = 2001 To 2005
Console.Write(ControlChars.Tab + "{0}", myCal.GetDaysInMonth(y, 2, myCal.Eras(i)))
Next y
Console.WriteLine()
Next i
End Sub
End Class
'This code produces the following output.
'
'YEAR 2001 2002 2003 2004 2005
'CurrentEra: 28 28 28 29 28
'Era 1: 28 28 28 29 28
注釈
たとえば、このメソッドは、yearが閏年かどうかに応じて、2 月の 28 または 29 (month = 2) を返します。