다음을 통해 공유


DateTime.DaysInMonth 메서드

지정된 월과 연도의 날짜 수를 반환합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Function DaysInMonth ( _
    year As Integer, _
    month As Integer _
) As Integer
‘사용 방법
Dim year As Integer
Dim month As Integer
Dim returnValue As Integer

returnValue = DateTime.DaysInMonth(year, month)
public static int DaysInMonth (
    int year,
    int month
)
public:
static int DaysInMonth (
    int year, 
    int month
)
public static int DaysInMonth (
    int year, 
    int month
)
public static function DaysInMonth (
    year : int, 
    month : int
) : int

매개 변수

  • year
    연도
  • month
    월(1부터 12까지)

반환 값

지정된 year에 속한 month의 날 수입니다. 예를 들어, 2월의 month가 2이면, 반환 값은 year가 윤년인지 여부에 따라 28이나 29가 됩니다.

예외

예외 형식 조건

ArgumentOutOfRangeException

month가 1보다 작거나 12보다 큰 경우

- 또는 -

year가 1보다 작거나 9999보다 큰 경우

예제

다음 코드 예제에서는 DaysInMonth 메서드를 사용하는 방법을 보여 줍니다.

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)
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 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 );
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에서 지원

참고 항목

참조

DateTime 구조체
DateTime 멤버
System 네임스페이스