Calculates the day of the week that is part of the year, and the time between Monday and Sunday.

Source: Internet
Author: User

Resources:

  The week algorithm refers to the method defined by ISO8601, if you have questions about this, please see: http://en.wikipedia.org/wiki/ISO_week_date

JS Code implementation:

var normalyear = [0,31,59,90,120,151,181,212,243,273,304,334];
var leapyear = [0,33,60,91,121,152,182,213,244,274,305,335];

      var nowdate = new Date ();

var datestr = Nowdate.format (' yyyy-mm-dd ');

var year = parseint (datestr.substring (0,4));

var mon = parseint (datestr.substring (5,8));

var day = parseint (datestr.substring (8,10));

var Numberofweek = parseint (Nowdate.getday ()); //

var orginday = 0;
if (Isleapyear (year)) {
Orginday = normalyear[numberofweek+1] + day;
}else{
Orginday = leapyear[numberofweek+1] +day;
}
var weekNum = (Orginday-numberofweek +10)/7; This is the result, which week of the year
WeekNum = weeknum.tostring (). substring (0,weeknum.tostring (). IndexOf ("."));
if (Numberofweek = = 0) {
Begtime = Begtime.add (-(1000*60*60*24) *6). Format (' Yyyy-mm-dd ');
EndTime = Endtime.format (' yyyy-mm-dd ');
}else{
Begtime = Begtime.add (-((1000*60*60*24)) * (numberOfWeek-1)). Format (' Yyyy-mm-dd ');
EndTime = Endtime.add (((1000*60*60*24)) * (7-numberofweek)). Format (' Yyyy-mm-dd ');
}
Begtime, endTime means the time of the week from Monday to the weekend.

      function Isleapyear (year) {//To determine if a leap year

if ((year%4) ==0 && (Year%100!=0)) | | (Year% 400 = = 0)) {

return true;
}
return false;
}

Calculates the day of the week that is part of the year, and the time between Monday and Sunday.

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.