+ 1

difference between 2 dates

how to check difference between 2 dates in JavaScript output should be like in years , months, days,hours,mins,sec

9th Mar 2018, 2:46 PM
Vikraant
1 Respuesta
+ 1
$(function() { var startDate = new Date("2018-03-07"), endDate = new Date(), diff = new Date(endDate - startDate), days = parseInt(diff/1000/60/60/24), hours = parseInt((diff/(1000*60*60)) % 24), minutes = parseInt((diff/(1000*60)) % 60), seconds = parseInt((diff/1000) % 60); document.write("Days: " + days + "<br>" + "Hours: " + hours + "<br>" + "Minutes: " + minutes + "<br>" + "Seconds: " + seconds + "<br>" + "D:H:M:S Format: " + days + ":" + hours + ":" + minutes + ":" + seconds); }); :::::: OUTPUT :::::::: Days: 2 Hours: 15 Minutes: 22 Seconds: 34 D:H:M:S Format: 2:15:22:34
9th Mar 2018, 3:22 PM
Fata1 Err0r
Fata1 Err0r - avatar