0

I m tryinng to get time diffrence using javascript. I m implementing this things in iformbuilder.

Code

var date1 = $(".date1").val();
var date2 = $(".date2").val();
var d1=new Date(date1);
var d2=new Date(date2); 
var total=(((d2-d1)/1000*60)/60)

E.g

date1=2014/03/26 05:03
date2=2014/03/26 06:05

Expected output:

1:02

Current output:

3720
user3068785
  • 116
  • 7
  • possible duplicate of [Convert seconds to HH-MM-SS with JavaScript?](http://stackoverflow.com/questions/1322732/convert-seconds-to-hh-mm-ss-with-javascript) (you already know how to get the difference, `d2 - d1` - you have a formatting issue.) – Amadan Mar 26 '14 at 06:14
  • There are many assumptions here. What about the DST, timezone and what if the date changes? will the day, month and year of date will be same always. – Vamsi Krishna Mar 26 '14 at 06:15

2 Answers2

1

The currentOutput is the difference in seconds. You can get the hours and minutes from it as:

var hrs = Math.floor(total/3600, 10);
var mins = (total%3600)/60;
techfoobar
  • 65,616
  • 14
  • 114
  • 135
0

Have you try this

var d1 = new Date();
var d2 = new Date();
document.write("Your Operation took  " + (d2.getTime() - d1.getTime()) + " milliseconds");
Nayeem Mansoori
  • 821
  • 1
  • 15
  • 41