。 Solve 2000 problems
function y2k (number) {return (number < 1000) number + 1900:number;}
2. Check whether the date is legal
When the input parameter is IsDate (DD,MM,CCYY), it means to check the year, month, day
When the input parameter is IsDate (DD,MM) indicates the default year is when
When the input parameter is IsDate (DD) indicates the default year, the month is the current date
Note that the input month is guaranteed to be within 1-12.
function IsDate (day,month,year) {
var today = new Date ();
Year = ((!year)-Y2K (Today.getyear ()) year);
Month = ((!month)? Today.getmonth (): month-1);
if (!day) return False
var test = new Date (year,month,day);
if ((Y2K (test.getyear ()) = = year) &&
(Month = = Test.getmonth ()) &&
(Day = = Test.getdate ()))
return true;
Else
return False
}
The following is an example of an invocation:
if (IsDate (31,2,1997))
document.write ("valid");
Else
document.write ("invalid");