+ 1

Create a Javascript algorithm to compute the difference between two dates in days: hours: min

CHALLENGE :::::: Javascript date algorithm

17th Oct 2017, 2:02 PM
Eruditegr
Eruditegr - avatar
2 ответов
+ 7
var d1 = new Date('05/07/2016'); var d2 = new Date('01/15/2017'); alert(Math.ceil(Math.abs(d2.getTime()-d1.getTime())/86400000));
17th Oct 2017, 2:34 PM
Dapper Mink
Dapper Mink - avatar
0
my attempt: var d = new Date("Wed Mar 25 2015 09:56:24 GMT+0100 (W. Europe Standard Time)"); //var d1 = new Date(2015, 2, 23 ,10,22); //var d2 = new Date('01/15/2017'); //credits to previous answer var d1 = new Date("Wed Mar 5 2015 09:56:24 GMT+0100 (W. Europe Standard Time)"); var d3 = d.getTime()-d1.getTime(); var days =Math.floor(Math.abs(d3/86400000)); //document.write ('\n'+days); var hours = Math.floor((d3-days*86400000)/3600000); var mints = Math.floor((d3-days*86400000-hours*3600000)/60000); var an= days+ " days: "+Math.abs(hours)+" hours: "+Math.abs(mints)+" minutes " ; document.write(an); https://code.sololearn.com/WUN4rJEWPM25/?ref=app
17th Oct 2017, 5:41 PM
Siva Shankar
Siva Shankar - avatar