HTML Component (HTML components) quad

Source: Internet
Author: User
Tags date array return
= = Write Calendar one = = =

When Calendar.html calls Mycal:calendar, the calendar for the month is displayed on the page, and the function setcal () is the main program segment that initializes some variables and invokes the drawcal () function. We also used three other functions: Getmonthname (), GetDays (), and Leapyear (). Let's start with the last function:

The GetDays () function receives which month and year values, and creates an array of 12 elements that is used to hold the number of days per month, and which year is used to determine whether a leap years, in leap months, February is 29 days, and not leap is 28 days. The function returns the number of days in the specified month.

The following is GetDays ():

function getdays (month, year) {
Create array to hold number of on each month
var ar = new Array (12);
Ar[0] = 31; January
AR[1] = (leapyear (year))? 29:28; February
Ar[2] = 31; March
AR[3] = 30; April
Ar[4] = 31; May
AR[5] = 30; June
Ar[6] = 31; July
AR[7] = 31; August
AR[8] = 30; September
AR[9] = 31; October
AR[10] = 30; November
AR[11] = 31; December

Return number is in the specified month (parameter)
return Ar[month];
}

= = Write Calendar one = = =

If the specified number of years can be divisible by 4, then the Leapyear () function returns "true", otherwise it returns "false":

function Leapyear (year) {
if (year% 4 = 0)//Basic rule
return true; is leap year
* Else//else not needed when statement are "return"
return false; Is isn't leap year
}
The Getmonthname () function returns the name of the specified month:
function Getmonthname (month) {
Create array to hold name of each month
var ar = new Array (12);
Ar[0] = "January";
AR[1] = "February";
AR[2] = "March";
AR[3] = "April";
AR[4] = "may";
AR[5] = "June";
AR[6] = "July";
AR[7] = "August";
AR[8] = "September";
AR[9] = "October";
AR[10] = "November";
AR[11] = "December";

Return name of Specified month (parameter)
return Ar[month];
}

= = Write Calendar one = = =

The setcal () function is the main module and we call it in the first line of the script. The function creates a date object for the day (now), and the first day of the month (firstdayinstance). With these objects, the setcal () function parses all information about the first day, day, and last day of the one month.

function setcal () {
Standard Time Attributes
var now = new Date ();
var year = Now.getfullyear ();
var month = Now.getmonth ();
var monthname = getmonthname (month);
var date = Now.getdate ();
now = null;

Create instance of month, and extract on which it occurs
var firstdayinstance = new Date (year, month, 1);
var firstday = Firstdayinstance.getday ();
Firstdayinstance = null;

Number of days in current month
var days = getdays (month, year);

Call function to draw calendar
Drawcal (FirstDay + 1, days, date, monthname, year);
}



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.