2015년 8월 7일 금요일

[ C# ] 올바른 날짜인지 여부를 확인 (IsDate)

•public sealed class Validation {
•
•  #region IsDate 방법
•
•    /// ----------------------------------------------- -------------------------------
•    /// <summary>
•    /// 지정된 연도 월 일 올바른 날짜인지 여부를 반환합니다. </ summary>
•    /// <param name = "iYear">
•    /// 검사 대상이되는 해. </ param>
•    /// <param name = "iMonth">
•    /// 검사 대상이되는 달. </ param>
•    /// <param name = "iDay">
•    /// 검사 대상이되는 날. </ param>
•    /// <returns>
•    /// 지정된 연도 월 일 올바른 날짜이면 true. 그렇지 않으면 false입니다. </ returns>
•    /// ----------------------------------------------- -------------------------------
•    public static bool IsDate (int iYear, int iMonth, int iDay) {
•        if ((DateTime.MinValue.Year> iYear) || (iYear> DateTime.MaxValue.Year)) {
•            return false;
•        }
•
•        if ((DateTime.MinValue.Month> iMonth) || (iMonth> DateTime.MaxValue.Month)) {
•            return false;
•        }
•
•        int iLastDay = DateTime.DaysInMonth (iYear, iMonth);
•
•        if ((DateTime.MinValue.Day> iDay) || (iDay> iLastDay)) {
•            return false;
•        }
•
•        return true;
•    }
•

•  #endregion

댓글 없음:

댓글 쓰기