JavaScript Date processing function encyclopedia (1/7)

Source: Internet
Author: User

。 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");

Home 1 2 3 4 5 6 7 last

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.