Dynamic Clock Time and Countdown in #AfterEffects

In this video we will see how we can create dynamic countdown in Adobe After Effects.

· 1 min read

Code


// clock start time HH:MM:SS
var clockStartAt = "06:00:10";

//Count Up/ Down rate
var rate = -1;

cStr = clockStartAt.split(":");

// count all seconds for givin time
var clockStart = (parseInt(cStr[0]) * 3600) + (parseInt(cStr[1]) * 60) + parseInt(cStr[2]);

// calculate clock time from inPoint of the current text Layer.
var clockTime = Math.max( clockStart + rate * (time - inPoint), 0);

var t = Math.floor(clockTime);

var sec = Math.floor( t % 60 );
var min = Math.floor( (t % 3600) / 60 );
var hour = Math.floor( (t % (3600 * 60)) / 3600 );

// to prefix ZERO, we need to create a function
function padZero(n){
    if (n < 10 ) return "0"+n else return "" + n;
}

// display time with padZero function
padZero(hour) + ":" + padZero(min) + ":" + padZero(sec);