This article mainly describes jsCalender controls and writes a simple calendar control by yourself. Interested friends can refer to some functions about js date recently, I suddenly thought of the calendar control, so I tried to write one. As a background programmer, I have a limited level. Let's take a look at the example I wrote and learn and make progress together!
First, a common date function:
Date (year, month, day)
Var date = new Date ();
Get year
Var year = this. date. getFullYear ();
Obtain the month. Here is the monthly index, so we need to add 1 more.
Var month = this. date. getMonth () + 1;
Obtain the number of the current day
Var day = this. date. getDate ();
Returns the day of the week. 0. Sunday 1. Monday 2. Tuesday 3. Wednesday 4. Thursday 5. Friday 6. Saturday.
Var week = this. date. getDay ();
Obtain the number 1 of the week in the current month.
var getWeekDay=function(year,month,day){ var date=new Date(year,month,day); return date.getDay(); } var weekstart= getWeekDay(this.year, this.month-1, 1)
Obtain the number of days in the current month
var getMonthDays=function(year,month){ var date=new Date(year,month,0); return date.getDate(); }var monthdays= this.getMonthDays(this.year,this.month);
Well, we have used so many parameters. The following are some operations and judgments on the day of the week corresponding to the date, and dynamic tag splicing. The example I wrote is directly sent below:
: