JavaScript to determine whether a leap year's datetime package _ Time Date

Source: Internet
Author: User
To see the source code:
Copy Code code as follows:

/**
* Jscript.datetime Package
* This package contains utility functions for working with dates and times.
*/
/* Namespace */
if (typeof JScript = = ' undefined ') {
JScript = function () {}
}

Jscript.datetime = function () {}

/**
* This function would return the number of days in a given month and year,
* Taking leap years into account. (This function returns the number of days for a given year, month, and takes into consideration the case of leap years)
*
* @param inmonth the month, where January = 1 and December = 12.
* @param inyear the year to check the month in.
* @return The number of the specified month and year.
*/
Jscript.datetime.getNumberDaysInMonth = function (Inmonth, inyear) {

Inmonth = inMonth-1;
var leap_year = this.isleapyear (inyear);
if (leap_year) {
Leap_year = 1;
} else {
leap_year = 0;
}
/*4, 6, 9, November for 30 days, notice above inmonth = inmonth-1*/
if (Inmonth = 3 | | inmonth = 5 | | | inmonth = 8 | | inmonth = = 10) {
return 30;
else if (Inmonth = 1) {/*2 Month is 28 or 29 days, depending on whether it is a leap year * *
return + leap_year;
else {//other month is 31 days * * *
return 31;
}

}//End Getnumberdaysinmonth ().


/**
* This function would determine if a given year are a leap year.
* (This function is used to determine whether it is a leap year)
* @param inyear to check.
* @return True If Inyear is a leap year, false if not.
*/
Jscript.datetime.isLeapYear = function (inyear) {

if (inyear% 4 = 0 &&! ( Inyear% 100 = 0)) | | Inyear% 400 = 0) {
return true;
} else {
return false;
}

}//End Isleapyear ().

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.