Once every eight hundred years, there will be 5 Saturday, 5 Saturday, 5 Saturday, and 5 Saturday (a good solution for js Date object exercises) in July [original]

Source: Internet
Author: User

This morning, I read yuanyou's article once every eight hundred years ......, I thought if it was the first time in eight hundred, I used js to verify it myself;

You can use the following methods to determine whether there are five Saturday, five Saturday, and five Saturday: 1: The month must have 31 days.

2: The first day of the month must be the day of the week 5. (My judgment is that the last day is Sunday, and the last day is to facilitate the determination of the number of days in the month)

<Script>
// Move back one month
Function prevMonth (thisMonth, thisYear ){
If (thisMonth = 1 ){
ThisM = 12;
ThisY = (thisYear-1 );
}
Else {
ThisM = (thisMonth-1 );
ThisY = thisYear;
}
}

// Move forward one month
Function nextMonth (thisMonth, thisYear ){
If (thisMonth = 12 ){
ThisM = 1;
ThisY = (thisYear + 1)
}
Else {
ThisM = (thisMonth + 1 );
ThisY = thisYear;
}
}
// Convert to short Date Format
Function to1_date (date ){
Var dateStr = date. getFullYear () + "-" + (date. getMonth () + 1) + "-" + date. getDate ();
Return dateStr;
}

Var dtNow = new Date ();
Var thisM = dtNow. getMonth () + 1;
Var thisY = dtNow. getFullYear ();
Var arrayRecord = [];
While (thisY> = 1900 ){
PrevMonth (thisM, thisY );
Var lastDayOfPrevMonth = new Date (thisY, thisM, 0 );
If (lastDayOfPrevMonth. getDay () = 0 & lastDayOfPrevMonth. getDate () = 31 ){
ArrayRecord. push (to1_date (lastDayOfPrevMonth ));
}
}

Document. write (arrayRecord. join ("\ r "));
</Script>

The previous February has five Friday, five Saturday, and the five Thursday are:

2005-7

 

Thank you for leaving a message, please declare the source (http://www.cnblogs.com/flowerszhong ).

 

 

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.