I am new to Momentjs. I am trying to use it to convert milliseconds to hours and minutes. Below, x is milliseconds
x = 433276000 var y = moment.duration(x, 'milliseconds').asHours;
Can anyone help?
To convert milliseconds to hours and minutes:Divide the milliseconds by 1000 to get the seconds. Divide the seconds by 60 to get the minutes. Divide the minutes by 60 to get the hours.
Convert Milliseconds to minutes using the formula: minutes = (milliseconds/1000)/60). Convert Milliseconds to seconds using the formula: seconds = (milliseconds/1000)%60). The print output from Milliseconds to minutes and seconds.
I ended up doing this...
var x = 433276000 var tempTime = moment.duration(x); var y = tempTime.hours() + tempTime.minutes();
Try this:
var x = 433276000 var d = moment.duration(x, 'milliseconds'); var hours = Math.floor(d.asHours()); var mins = Math.floor(d.asMinutes()) - hours * 60; console.log("hours:" + hours + " mins:" + mins);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With