JS to find the difference between the two dates, ie and other browser differences

Source: Internet
Author: User

Today, a simple question has been encountered: based on the two dates provided, travel values are calculated. Think very simple, get two milliseconds of the date, make the difference and then convert to the corresponding units:

The code is as follows:

      Get two date interval years function Yeardiff (begindate,enddate) {//date difference of milliseconds var minisecond=enddate.gettime ()-begindate.gettime (); Return Math.floor (minisecond/(24*3600*1000*360)); Interval year//return Math.floor (minisecond/(24*3600*1000)); Interval days}    

Normally this is done, but many times we get a string of dates at the front desk (e.g. ' 2008-06-07 '), and then the current date is poor. Normal will convert the previous to the date format, and then the difference:

    var begindate= "2008-06-07";      begindate= new Date (begindate);      var nowdate=new Date ();  var diffyear= yeardiff (begindate,nowdate);

  

This should be done, pro-test Firefox no problem, ie results: NAN. Later found to be IE in the analysis of begindate transformation when there is a problem.

Begindate = new Date (Begindate.replace (/-/g, "/"));

So ok!! Do not know what the situation, notes

2015-05-05 20:27

JS to find the difference between the two dates, ie and other browser differences

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.