JS to find two days of difference between dates

Source: Internet
Author: User
Tags date1

Recently do the system often need to use JS about time, I am not very familiar with JS to write a variety of time, date code, are online Baidu, basic can see understand, but they are not written out, so the use of JS should be in the blog record, deepen the impression.

/** * Ask for two days difference between dates * @param startdatestr * @param enddatestr * @returns */function getDays (startdatestr, enddatestr) {var sep Aratorstr = "-"; var startdate;var enddate;var idays;startdate = Startdatestr.split (separatorstr); endDate = Enddatestr.split (SEPARATORSTR), var date1 = new Date (startdate[0],startdate[1]-1,startdate[2]), var date2 = new Date ( Enddate[0],enddate[1]-1, enddate[2]); idays = parseint (Math.Abs (DATE1-DATE2)/1000/60/60/24);//difference milliseconds conversion 2 for day return iDays ;}

  

JS to find two days of difference between 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.