A simple example _javascript technique for calculating the working day of two days period in JS

Source: Internet
Author: User

The

instance is as follows:

//start date,  /pattern/is the definition of regular expression, pattern is the content to match, only for the first symbol match, G is the global match flag   var begindate = new Date ("2013-01-01". Replace (/-/g, "/"));
End date var enddate = new Date ("2013-01-31". Replace (/-/g, "/"));
The date difference value, which contains the days of the week 6th, 86400000=1000*60*60*24.
var workdayval = (enddate-begindate)/86400000 + 1;
The remainder of the work var remainder = workdayval% 7;//Work down the divisor var divisor = Math.floor (WORKDAYVAL/7);

var weekendday = 2 * DIVISOR;
Week of starting date, week value has (1,2,3,4,5,6,0) var nextday = Begindate.getday (); Start the week from the start date to traverse remainder day for (var tempday = remainder; tempday>=1; tempday--) {//First day without adding 1 if (tempday = remainder)
  {nextday = nextday + 0;
  else if (tempday!= remainder) {nextday = nextday + 1;
  //Sunday, change to 0 if (NextDay = 7) {nextday = 0;
  //week 6th if (nextday = 0 | | nextday = = 6) {Weekendday = weekendday + 1;
}//Actual work (days) = end to End date difference-number of weeks 6th.
Workdayval = Workdayval-weekendday; 

This JS in the calculation of two days during the working day of the simple example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.