How To Convert Seconds To Minutes Using Javascript...?
I am making a online quiz system and i want to convert my timer from seconds to minutes and seconds. Please help me to solve this problem here is my code
Solution 1:
Try something like this:
functionconvert(value) {
returnMath.floor(value / 60) + ":" + (value % 60 ? value % 60 : '00')
}
Solution 2:
Solution 3:
I would suggest you simply use this function (taken from here) which transforms a number of seconds into an string representing the hours, minutes and seconds in format HH:MM:SS:
functionsecondsToTimeString(seconds) {
var minutes = 0, hours = 0;
if (seconds / 60 > 0) {
minutes = parseInt(seconds / 60, 10);
seconds = seconds % 60;
}
if (minutes / 60 > 0) {
hours = parseInt(minutes / 60, 10);
minutes = minutes % 60;
}
return ('0' + hours).slice(-2) + ':' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2);
}
Post a Comment for "How To Convert Seconds To Minutes Using Javascript...?"