Reputation: 2213
I have a result in milliseconds and I am trying to display it as Hours and Minutes using Momentjs.
var x = 161545000;
var tempResult = moment.duration(x);
var formattedX = tempResult.asHours() + 'h ' + tempResults.minutes() + 'm ';
What is being displayed:
2.2701202777777776h 16m
What I want, but can't seem to format it right:
2h 16m
Upvotes: 2
Views: 5894
Reputation: 24502
How about using Math.floor()
?
var formattedX = Math.floor(tempResult.asHours()) + 'h ' +
Math.floor(tempResults.minutes()) + 'm ';
Or, better yet, use the Moment#hours()
method instead of Moment#asHours()
:
var formattedX = tempResult.hours() + 'h ' + tempResults.minutes() + 'm ';
Upvotes: 6