js-displays the specified number of weeks in Monday and Sunday, the first and last day of the specified month-----------personal Baidu collation

Source: Internet
Author: User

Job requirements, given the number of cycles for a year, you need to display the week's Monday and Sunday as well as the first and last day of the specified month

Baidu after finishing show posted, that the individual still do not understand why, I hope someone can explain

Post code:

<script type= "Text/javascript" >varIweek =function(year, week) {varD =NewDate (year, 0, 1);//Initialization Date D indicates the first day of the input year while(D.getday ()! = 1) {d.setdate (d.getdate ()+ 1); }            varto =NewDate (year + 1, 0, 1)//Indicates the first day of the next yearvari = 1; vararr = ';  for(varfrom = D; From <to ;) {                if(i = =week) {arr+=from.getfullyear () + "/" + (From.getmonth () + 1) + "/" + from.getdate () + "-";
getFullYear () returns the year, GetMonth () returns the month, but the month defaults from 0, so +1;getdate () returns the day}varj = 6; while(J > 0) {from.setdate (from.getdate ()+ 1); if(i = =week) { if(j==1) {//If it is Sunday arr+=from.getfullyear () + "/" + (From.getmonth () + 1) + "/" +from.getdate (); //Arr.push (from.getfullyear () + "/" + (From.getmonth () + 1) + "/" + from.getdate ());}} J--; } if(i = =week) { returnarr; } from.setdate (From.getdate ()+ 1); I++; } } functionImonth (year, month) {varDay =NewDate (year,month,0); varTime = Day.getfullyear () + "/" + (Day.getmonth () + 1) + "/01-" +day.getfullyear () + "/" + (Day.getmonth () + 1) + "/" +day.getdate (); returnTime ; }</script>

js-displays the specified number of weeks in Monday and Sunday, the first and last day of the specified month-----------personal Baidu collation

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.