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