Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert milliseconds to hours and minutes using Momentjs

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?

like image 286
user3214545 Avatar asked Apr 08 '14 13:04

user3214545


People also ask

How do you convert milliseconds to hours and minutes?

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.

How do you convert milliseconds to minutes and seconds?

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.


2 Answers

I ended up doing this...

var x = 433276000 var tempTime = moment.duration(x); var y = tempTime.hours() + tempTime.minutes(); 
like image 92
user3214545 Avatar answered Oct 11 '22 15:10

user3214545


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); 
like image 28
closure Avatar answered Oct 11 '22 15:10

closure