|
指定の年月日が有効であるか判定する関数を作る。 //*********************************************************
// 有効な日付かどうかを確かめる。
// 1 <= 月 <= 12
// 1 <= 日 <= その月の最終日
// で有効
// 有効な日付であれば真、さもなくば偽を返す
//*********************************************************
int IsGoodDate( int Year, int Month, int Day )
{
return ((Month>=1)&&(Month<=12)&&(Day>=1)&&(Day<=DaysInMonth(Year,Month)));
}//IsGoodDate
//*********************************************************
// 指定された月の最終日を返す
// 入力された月が不正(1月〜12月の範囲外)であれば0を返す
//*********************************************************
int DaysInMonth( int nYear, int nMonth )
{
const int nDaysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( ( nMonth < 1 ) || ( 12 < nMonth ) )
return 0;
if ( (2 == nMonth) && IsLeapYear(nYear) )
return 29;
return nDaysInMonth[nMonth-1];
}//DaysInMonth
関連 | |
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
>> Amazon.co.jp 『たまゆら童子』 へ
>> 楽天ブックス 『たまゆら童子』 へ