1

I'm using momentJS to find the difference between two times and format to hh:mm:ss. Ver: "moment": "~2.10.6"

The problem I'm having is an extraneous 7 hours being added to a time whose difference is only 1 minute, 1 second.

var diff_ms = moment('2016-07-29 10:35:18').diff('2016-07-29 10:34:17');

61000

var diff = moment(diff_ms).format('hh mm ss')

"07 01 01"

Convert milliseconds to hours and minutes using Momentjs says to specify the time unit as milliseconds, moment.duration(x, 'milliseconds');, but since it's returning the correct minutes and seconds (01 01), it seems it's correctly defaulting to milliseconds.

I can do this the "un-momentJS" way:

var a = moment.duration(61000, 'milliseconds');

a: n {_milliseconds: 61000, _days: 0, _months: 0, _data: Object, _locale: l}

var b = a.hours() + ':' + a.minutes() + ':' + a.seconds();

b: 0:1:1

But don't have an easy way of formatting this output to hh:mm:ss using string concatenation like this.

Community
  • 1
  • 1
user3871
  • 12,432
  • 33
  • 128
  • 268

0 Answers0