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 ().