This article mainly introduces JS date addition and subtraction and date calculation code. For more information, see
1. date minus the number of days equals to the second date
Function cc (dd, dadd) {// you can add error processing var a = new Date (dd) a =. valueOf () a = a-dadd * 24*60*60 * 1000a = new Date (a) alert (. getFullYear () + "year" + (. getMonth () + 1) + "month" +. getDate () + "day")} cc ("12/23/2002", 2)
I have to add some resources here, wasting a lot of time to draw lessons:
Time code of Javascript
0-11: The number is 1-12 months. var a = new Date (, 6). The result is-6.
0-6 indicates the week
1-31 represents the date
0-23 hours
0-59 minutes, seconds
II. // Difference between two dates (d1-d2 ).
function DateDiff(d1,d2){ var day = 24 * 60 * 60 *1000;try{ var dateArr = d1.split("-"); var checkDate = new Date(); checkDate.setFullYear(dateArr[0], dateArr[1]-1, dateArr[2]); var checkTime = checkDate.getTime(); var dateArr2 = d2.split("-"); var checkDate2 = new Date(); checkDate2.setFullYear(dateArr2[0], dateArr2[1]-1, dateArr2[2]); var checkTime2 = checkDate2.getTime(); var cha = (checkTime - checkTime2)/day; return cha; }catch(e){ return false;}}//end fun
Iii. application: