Search code examples
javascriptafter-effects

How would I go about fixing this timer in After Effects?


I'm attempting to make a timer for my video in AE, but when the timer gets to 10 minutes, an extra 0 is added to the front of the counter.

enter image description here

Any idea on how I can fix this?

sek = Math.floor(time%60);
min = Math.floor(time/60);



if(sek<10)
{
    "0" + min +":0" + sek;
}
else
{
    "0" + min +":" + sek;
}

Solution

  • There are four scenarios you should watch out for as represented below. The issue has a simple fix, trying this out should work

    
    sek = Math.floor(time%60);
    min = Math.floor(time/60);
    
    if(min<10 && sek<10)
    {
        "0" + min +":0" + sek;
    }
    else if(min<10 && sek>=10)
    {
       "0" + min +":" + sek;
    }
    else if(min>=10 && sek<10)
    {
        min + ":0" + sek;
    }
    else if (min>=10 && sek>=10)
    {
        min +":" + sek;
    }