怎么样判断是否为日期类型?
该方法可以验证带格式的的日期
格式在:string[] date = strIn.Split(new char[]{'格式'},格式可以指定,比如‘-’,则要验证的日期必须符合2006-10-10这种格式。
//验证年-月-日
publicstaticboolIsValidDate(stringstrIn)

...{
boolresult=false;
if(strIn.Length<=10&&strIn.Length>=8)

...{

string[]date=strIn.Split(newchar[]...{'-'});
if(date.Length==3)

...{
try

...{
intyear=Convert.ToUInt16(date[0],10);
intmonth=Convert.ToInt16(date[1],10);
intday=Convert.ToInt16(date[2],10);
result=CheckIsValidDate(day,month,year);
}
catch

...{
result=false;
}
}
}
returnresult;
}
privatestaticboolCheckIsValidDate(intday,intmonth,intyear)

...{
if(month>12||month<1)
returnfalse;
if(day>31||day<1)
returnfalse;
if(day>DateTime.DaysInMonth(year,month))
returnfalse;
returntrue;
}
本文地址:
http://www.45fan.com/dnjc/70554.html