Reputation: 1016
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
Upvotes: 0
Views: 5895
Reputation: 1016
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);
Upvotes: 1
Reputation: 50540
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.
Upvotes: 0