0

i'm trying to calculate the difference between two UTC Datetime Strings with angular-momentjs like shown below:

var start = "1970-01-01T11:03:00.000Z";
var end = "1970-01-01T11:15:00.000Z";

var duration = $moment.utc($moment(end).diff($moment(start))).format("hh:mm");

when i execute the code above, the duration should be 00:12 but actually it is 12:12. I don't understand why and how to fix it.

julian
  • 51
  • 1
  • 7
  • Possible duplicate of [Get the time difference between two datetimes](http://stackoverflow.com/questions/18623783/get-the-time-difference-between-two-datetimes) – Matt Johnson-Pint May 01 '16 at 17:16

1 Answers1

1

You are actually creating a moment.js object for 1970-01-01T00:12:00.000Z, then getting the time as hour and minutes. The token "hh" is for 12 hour time, so you're seeing "12" for 12am. If you want to see 00:12, use the token "HH" which gives 24 hour time: 00:12.

RobG
  • 142,382
  • 31
  • 172
  • 209