javascript - How to convert millisecond into the correspond time? -


i'm trying convert dynamic value milliseconds this:

1800000

into correspond time, should 30 minutes. code:

var time = new date(milliseconds); console.log("time => " , time); var m = time.getminutes();           console.log("m => ", m); 

time => thu jan 01 1970 08:00:00 gmt+0100 (ora solare europa occidentale)
m => 30

this correct if try milliseconds value => 25200000

m return => 0

there's correct way return correspond minutes?

date() objects overkill here. it's division:

var minutes = milliseconds / (1000 * 60); 

or, if don't want fractional minutes,

var minutes = math.floor(milliseconds / (1000 * 60)); 

in example, you're turning milliseconds date -- date/time milliseconds ms past 1/1/1970. after hour has passed, getminutes() return 0 again, hours have incremented, etc.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -