Js-gets the week of two string dates

Source: Internet
Author: User
Tags date1

For example, "2017-04-01 23:00:00" is Saturday, "2017-04-28 23:00:00" is Friday, including the week of their respective, I really need to get the result is 5 weeks.

Started to do when the string ah, time format ah, and then found that there is absolutely no need, after all, I want only the period value just ....

The idea is really simple, is to get the start date of the week of the Monday date

Then use the Monday date and end date to compare, rounding up. We can get to this number.

varStart = "2017-04-01 23:00:00"; varEnd = "2017-04-28 23:00:00"; //start date of Monday        varMonday =showweekfirstday (start); //period difference between the start date's Monday distance end date        varCycle =WEEKSBETW (Monday, end); //returns the first day of the week of Nowdate        functionShowweekfirstday (nowdates) {varNowdate =NewDate (nowdates); varWeekfirstday =NewDate (Nowdate-(Nowdate.getday ()-1) * 86400000); returnWeekfirstday; }

  

Returns the number of weeks between two dates
function Weeksbetw (DATE11, Date22) {

var date1 = new Date (DATE11);
var date2 = new Date (DATE22);
The date1,date2 here are all date objects.

var dt1 = Date1.gettime ();

var DT2 = Date2.gettime ();

Rounding up

Return Math.ceil (Math.Abs (DT1-DT2)/1000/60/60/24/7);

}

Above ~

Js-gets the week of two string dates

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.