CREATE A FEW SIMPLE COUNTDOWN TIMERS IN AFTER EFFECTS EASILY! | Learn to write the expressions that you need to build a very simple or very complex timer in After Effects.

In this After Effects tutorial, we’ll dive into using a single text field and create a couple of VERY simple timers to kick things off and then we’ll write a bit more complex code to create a much more realistic and functional countdown timer that you have complete control over. You can choose the duration of the countdown and simply set it and forget it! Build the code once and have a countdown menu that you can use for any project anywhere.

*Tags: after effects, after effects tutorial, after effect CC, after effects tutorials, after effects timer, after effect countdown timer, after effects expressions, how to, how to expressions, after effects timer expressions, after effects countdown code, after effects countdown tutorial, after effects countdown clock, after effects countdown timer tutorial, after effects timer countdown, after effects timer tutorial, after effects timer expression, tutvid, nathaniel dodson, AE *

### Tutorial Recording Notes:

*Disclaimer: these are the actual notes I used to record this video and are written in a language you may or may not understand. Hopefully, you find them useful or cool.*

**Finished Code:**

*rateOfSpeed=1;*

*clockStartTime = thisComp.layer(“slider”).effect(“Slider Control”)(“Slider”)*60;*

*clockTimeNumber = Math.floor(clockStartTime – rateOfSpeed*time);*

*function addZero(n) {*

* if (n<10) return “0” + n else return n;*

*}*

*minutes = Math.floor(clockTimeNumber/60);*

*seconds = clockTimeNumber%60;*

*if (clockStartTime > 0 && time < clockStartTime) {*

* addZero(minutes) + “:” + addZero(seconds);*

*} else {“00:00”}*

**1. Basic counting upward timer:**

- Add text layer w/ any text in it (Font:Rail, Ultra Light, 350px, #00CFFF)
- Align to the center of the comp
- Find Source Text and Alt + Click to open for expression editing
- Type in “Math.floor(time);”
- Explain what this does

**2. Basic counting down timer:**

- Change expression to:
- “Math.floor(60 – time);”
- Explain what is happening
- Show the problem if we go past 60 seconds

**3. Advanced countdown timer:**

- Clear out the expressions we just made. The goal is going to be to create a timer that the user can input a number to and have it count down from that.
- Create a new null object and drag a slider onto it.
- Now we’ll first set a rate of speed for our timer. In this case we want it to drop 1 second at a time.
- Enter “rateOfSpeed=1;”
- Then create the starting time that will be controlled by the slider.
- Enter “clockStartTime=PICK WHIP TO THE SLIDER”
- Now the number displayed will be equal to whatever we input to the slider.
- Next let’s get After Effects to spit the continuously changing countdown number back at us. Here’s how we do that:
- Enter “clockTimeNumber = rateOfSpeed*time;”
- This returns a crazy string of numbers. Let’s simplify:
- Change “clockTimeNumber = Math.floor(rateOfSpeed*time);”
- Number looks better. Show how the rateOfSpeed can speed up the number output.
- We now need to link this to the slider number that is taken in by the clockStartingTime var
- Change “clockTimeNumber = Math.floor(clockStartTime – rateOfSpeed*time);”
- This essentially multiplies our rateOfSpeed variable of 1 by the time (frame number at which the playhead is) and then subtracts that by the clockStartTime variable.
- If our slider is set to 5, we will see a timer that starts at 5 and each second subtracts 1 from it. This is okay, but after 5 seconds we hit negative numbers and we still don’t have much control here.
- If I want a five minute timer I need 300 seconds (60*5=300) so let’s set our slider to 300 and check out the timer now.
- But making other people have to go all this seconds math isn’t good, so let’s make this easier. We can add “*60” to the end of the var that targets the number coming out of the slider.
- This multiplies that number by 60. This is bad for 300, but if we want a 5 minute timer, simply change the slider to 5 and you get five minutes.
- Now we need to transform the formatting of the timer. We need minutes and seconds.
- Enter “clockTimeNumber/60” and explain what this is and show what’s happening (including all the crazy decimals)
- Next, let’s create a var to hold the number for our minutes Enter: “minutes = Math.floor(clockTimeNumber/60);”
- Explain what I just did.
- Create another var on the line beneath that for the seconds Enter: “seconds = clockTimeNumber%60”
- Enter “minutes + “:” + seconds;”
- This will fill out type field with this text that the expressions are outputting
- Break this down and show what the divide by 60 does to minutes and what the modulus (%) does for our number as well.
- Let’s add some zeroes to our formatting to fix this strange looking thing that’s going on.
- We need to create a function to fix our little issue
- Enter “function addZero(n) {
- if (n<10) return “0” + n else return n;

- }” and explain what’s going on here.
- Replace “minutes + “:” + seconds;” with “addZero(minutes) + “:” + addZero(seconds);”
- Now we have to limit the slider to prevent the problem that arises when somebody tries to set a negative number.
- Create the ‘if’ statement “if (clockStartTime > 0) { }
- Paste the “addZero(minutes) + “:” + addZero(seconds);” within the ‘if’ statement.
- Explain what’s happening and run a quick test.
- Add “else {}”
- Fill “”00:00″” into that else statement and explain what I did placing that string of text.
- Test the slider by pushing it to -100.
- Nice!
- Now drag the playhead all the way until the end and see the negative numbers.
- Fix this by adding a logical operator to the ‘if’ statement alongside the “clockStartTime > 0” by adding “&&” (and) into those parentheses and make sure it looks like this:
- if (clockStartTime > 0 && time < clockStartTime) { }
- Explain what’s happening here.

WHere is the fixed code?

rateOfSpeed=1;

clockStartTime = thisComp.layer(“timer duration”).effect(“Control del deslizador”)(“Deslizador”)*60;

clockTimeNumber=Math.floor(clockStartTime – rateOfSpeed*time);

function addZero (n){

if (n<10) {return "0" + n}else {return n}

}

minutes = Math.floor(clockTimeNumber/60);

seconds = clockTimeNumber%60;

addZero(minutes) + ":" + addZero(seconds);

Hi Nathaniel, Thanks so much for the tutorial & function. You just made my work life so much easier! Quick question? How do I add milliseconds? I will definitely follow you!!

Thanks again

Pierre

Hi, I am trying to use your written code and tutorial, but After Effects keeps telling me there are syntax errors?

Not a code boffin, so would appreciate it if you guys could help!

It seems that with every update, something changes for how After Effects handles some of these tokens. I love using this expression so here is the updated code that worked for me in AE2022!

rateOfSpeed=1;

clockStartTime = thisComp.layer(“slider”).effect(“Slider Control”)(“Slider”)*60;

clockTimeNumber = Math.floor(clockStartTime – rateOfSpeed*time);

function addZero(n) {

if (n 0 && time < clockStartTime) {

addZero(minutes) + ":" + addZero(seconds);

}

else ("00:00")