System Namespace DateTime Structure
Returns the number of days in the specified month of the specified year.
[ VB ]
<Serializable>
Public Shared Function DaysInMonth ( _
ByVal year As Integer, _
ByVal month As Integer _
} As Integer
[ C# ]
[ Serializable ]
public static int DaysInMonth (
int year,
int month
};
[ C++ ]
[ Serializable ]
public: static int DaysInMonth (
int year,
int month
};
[ JScript ]
public Serializable
static function DaysInMonth (
year : int,
month : int
} : int;
- year
- The year.
- month
- The month ( a number ranging from 1 to 12 ).
The number of days in month for the specified year.
For example, if month equals 2 for February, the return value is 28 or 29 depending upon whether year is a leap year.
The below code snippet demonstrates using the DaysInMonth method.
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 );
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# |
VB |
DateTime Members