• We just upgraded the platform on which this website runs! Please inform @Jaxel of any issues.

Timer Using Minutes and Seconds

murray-johnson

New member
Again, awesome product. My question for this post, is it possible to get a timer to display only minutes and seconds? I film for soccer games and a soccer clock counts upwards and only uses minutes, so, for a standard hour and half game the clock should read 90:00 at the end of game and not 1:30:00.
 

Jaxel

Administrator
The tutorial shows:
Code:
function calcTimer(time)
{
    let neg = (time < 0) ? '- ' : '';
    time = Math.abs(time / 1000);
    
    hours = (Math.floor(time / 3600)).toString().padStart(2, '0');
    minutes = (Math.floor(time % 3600 / 60)).toString().padStart(2, '0');
    seconds = (time % 60).toFixed(1).toString().padStart(4, '0');
    
    return neg + hours + ' : ' + minutes + ' : ' + seconds;
}

Just replace that with:
Code:
function calcTimer(time)
{
    let neg = (time < 0) ? '- ' : '';
    time = Math.abs(time / 1000);
    
    minutes = ((Math.floor(time / 3600)) * 60 + Math.floor(time % 3600 / 60)).toString().padStart(2, '0');
    seconds = (time % 60).toFixed(1).toString().padStart(4, '0');
    
    return neg + minutes + ' : ' + seconds;
}