Converting Milliseconds To Nearest Minute In Javascript
Using javascript/jquery how can you convert from an integer duration in milliseconds to the nearest minute? For example: 900000 milliseconds should equal 15 minutes
Solution 1:
You can use the following:
var millisecondVal = 900000;
var minuteVal = millisecondVal / 60000;
alert(minuteVal);
minuteVal = Math.round(minuteVal);
alert(millisecondVal + "miliseconds value to the nearest minute:" + minuteVal);
Solution 2:
Being 1 minute equal to 60000 milliseconds, you can simply use something like Math.round(your_elapsed_time/60000)
.
In other terms: first of all divide by 1000 to find the number of seconds, secondly divide by 60 to find the number of minutes, finally round it to the nearest number.
Post a Comment for "Converting Milliseconds To Nearest Minute In Javascript"