クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
以前のバージョン
.NET Framework SDK 2.0
System
DateTime 構造体
DateTime メソッド
 DaysInMonth メソッド

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.NET Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
DateTime.DaysInMonth メソッド

指定した月および年の日数を返します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)

Visual Basic (宣言)
Public Shared Function DaysInMonth ( _
    year As Integer, _
    month As Integer _
) As Integer
Visual Basic (使用法)
Dim year As Integer
Dim month As Integer
Dim returnValue As Integer

returnValue = DateTime.DaysInMonth(year, month)
C#
public static int DaysInMonth (
    int year,
    int month
)
C++
public:
static int DaysInMonth (
    int year, 
    int month
)
J#
public static int DaysInMonth (
    int year, 
    int month
)
JScript
public static function DaysInMonth (
    year : int, 
    month : int
) : int

パラメータ

year

年。

month

月 (1 から 12 までの範囲の数)。

戻り値

指定した yearmonth の日数。 たとえば、month が 2 月を表す 2 に等しい場合、戻り値には、year が閏年かどうかによって 28 または 29 を返します。
例外の種類条件

ArgumentOutOfRangeException

month が 1 未満か、12 よりも大きい値です。

または

year が 1 未満か、9999 よりも大きい値です。

DaysInMonth メソッドのコード例を次に示します。

Visual Basic
Const July As Integer = 7
Const Feb As Integer = 2

' daysInJuly gets 31.
Dim daysInJuly As Integer = System.DateTime.DaysInMonth(2001, July)

' daysInFeb gets 28 because the year 1998 was not a leap year.
Dim daysInFeb As Integer = System.DateTime.DaysInMonth(1998, Feb)

' daysInFebLeap gets 29 because the year 1996 was a leap year.
Dim daysInFebLeap As Integer = System.DateTime.DaysInMonth(1996, Feb)
C#
const int July = 7;
const int Feb = 2;

// daysInJuly gets 31.
int daysInJuly = System.DateTime.DaysInMonth(2001, July);

// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System.DateTime.DaysInMonth(1998, Feb);

// daysInFebLeap gets 29 because the year 1996 was a leap year.
int daysInFebLeap = System.DateTime.DaysInMonth(1996, Feb);
C++
const int July = 7;
const int Feb = 2;

// daysInJuly gets 31.
int daysInJuly = System::DateTime::DaysInMonth( 2001, July );

// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System::DateTime::DaysInMonth( 1998, Feb );

// daysInFebLeap gets 29 because the year 1996 was a leap year.
int daysInFebLeap = System::DateTime::DaysInMonth( 1996, Feb );
J#
final int july = 7;
final int feb = 2;
// daysInJuly gets 31.
int daysInJuly = System.DateTime.DaysInMonth(2001, july);
// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System.DateTime.DaysInMonth(1998, feb);
// daysInFebLeap gets 29 because the year 1996 was a leap year.
int daysInFebLeap = System.DateTime.DaysInMonth(1996, feb);

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker