You were close. You just need to use the duration.asHours()
method (see the docs).
var duration = moment.duration(end.diff(startTime));
var hours = duration.asHours();
More Related Contents:
- Get the time difference between two datetimes
- “Deprecation warning: moment construction falls back to js Date” when trying to convert RFC2822 date in moment.js
- How to JSON stringify a javascript Date and preserve timezone
- Moment.js: Date between dates
- Moment Js UTC to Local Time
- How can I remove time from date with Moment.js?
- Format date and Subtract days using Moment.js
- from unix timestamp to datetime
- How to properly add 1 month to current date in moment.js
- Moment.js – How To Detect Daylight Savings Time And Add One Day
- Round a timestamp to the nearest date
- How to convert Moment.js date to users local timezone?
- moment.js isValid function not working properly
- new Date(2015,2,30) and new Date(‘2015-2-30’)
- Calculate age given the birth date in the format YYYYMMDD
- How do I get the difference between two Dates in JavaScript?
- Convert UTC Epoch to local date
- Get time of specific timezone [duplicate]
- Function to convert timestamp to human date in javascript [duplicate]
- How do I calculate how many seconds between two dates?
- javascript Date timezone issue
- Get the current year in JavaScript
- Get week of the month
- Convert normal date to unix timestamp
- why does javascript getMonth count from 0 and getDate count from 1?
- Javascript countdown using absolute timezone?
- Moment.js transform to date object
- Elegant method to generate array of random dates within two dates
- create javascript date UTC
- Making a live clock in javascript