Download Project File

How To Create a Custom Clock in After Effects

In this post, I will show you how to create a custom clock in After Effects. So without any further ado, let’s dive right in!

Alright, so we are in After Effects and this is what we are going to create today.
Clock in After Effects

As you can see, I have a clock and a slider. If I move the slider, it will automatically adjust the seconds of the clock in my composition. So the slider is synchronized with the clock.

Slider adjustable clock in Adobe After Effects

Also, when I go past 60 seconds on the slider, the clock will automatically convert seconds into minutes.

Past 60 seconds in After Effects custom clock

So if I leave the slider at 181.00 seconds, the clock will automatically convert the seconds to minutes and it will display it as 3 minutes and 1 second like so: 03:01. You get the idea.

past 60 seconds in After Effects

Now let me show you how to set this up!

Step 1:

Select 00:00 text in the timeline.

Select Text in Timeline After Effects

Step 2:

Select the Effects Control panel -> Right-Click -> Expression Controls -> Slider Control

Expressions Controls - Slider Control - After Effects

Slider in After Effects

Step 3:

Go inside of the 00:00 text layer -> Text -> Source Text

Source Text in After Effects

Step 4:

Press S twice to solo the Text Source.

Solo text source in After Effects keyboard shortcut

Step 5:

ALT+Left Click (OPT+Left Click on a Mac) on the Source Text stopwatch icon to activate the expression.

Activate Expression in After Effects

Step 6:

We are going to set some variables inside of the text box. I am going to say slider, you are going to equal (=) to and then I will pick whip to the Slider inside of our Effects Control Panel.

slider = effect(“Slider Control”)(“Slider”);

Pick whip to Slider in After Effects

Slider expressions in After Effects

Step 7:

Next, I am going to say slider modulus (%) 60:

slider = effect(“Slider Control”)(“Slider”);

slider%60

The slider%60 forces the clock to go to 0 when the slider goes past 60. Let me show you what I am talking about here.

Slider modulus 60 in After Effects

Right now our clock is set to 0 because the slider is 0.

However, if I move the slider past 60, it will reset our clock back to 0.

So for example, right now my slider is set to 65.00. We went over 60 by 5 seconds. So the clock reset at 60 and only kept 5. That is why we only see 5 on the clock. I hope that makes sense.

Going past 60 on slider in After Effects

So that is going to be our seconds. I am going to define it as seconds like so:

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;

Next, we are going to work on minutes.

Step 8:

So I am going to say min = and in here we are going say slider divided (/) by 60:

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = slider/60;

And then we are going to call the min expression by typing min like so:

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = slider/60;

min

As you can see, right now we have 1.25 in our composition and our slider is set to 75.00.

Value in After Effects

Now let’s reset our slider back to 0.00, which will also reset our composition clock to 0 as well.

Reset the slider to 0 in After Effects Effects Control Panel

If I move our slider to 5.00, you can see that the numbers on our clock kind of go crazy because it has a lot of decimals. It should say something like 0.083333333333.

Number with a lot of decimals in After Effects

The first value will always be 0 until we pass 60 on the slider.

Let me show you what I mean. Let’s move our slider past 60.0 to something like 61.00.

Going past 60 in After Effects Slider

As you can, the first value of our clock is no longer 0 but instead, it is now 1.0166

Step 9

Now let’s round it up and make it a little cleaner. To do that we are going to use math.floor expression. Let me show you what I am talking about here.

Let’s go back to our expression and add Math.floor to the min line like so:

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = Math.floor(slider/60);

min

So the floor will always keep it 0 until it goes past 9 and then it will give us 1.

Math floor expression in After Effects

So right now you can’t see anything in our composition because our clock is way over on the right side.

Can't see the clock in After Effects composition

Step 10

I am going to CTRL+ALT+HOME (CMD+OPT+HOME on a Mac) to Center the Pivot Point.

Center the pivot point in After Effects

Step 11

Then CTRL+HOME (CMD+HOME on a Mac) to Center the clock in the composition.

Center the clock in my composition in After Effects

Center in the composition in After Effects

So now if I move the slider, you can see that nothing is happening until I hit past 60.

Nothing is happening with the slider in After Effects

Past 60 in After Effects Slider

When I cross 60, then it gives me 1. So that is exactly what I want for the minutes to do.

Step 12

Now let’s set this up. Let’s go back to our text editor and add a few things to our expression. I am going to say min ++ and inside the ++ I am going to say +“:”+ and I will also add sec at the end of this expression. So it should look like this:

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = Math.floor(slider/60);

min +”:”+sec

Now if I let go, here is what I have:

Minutes and seconds in After Effects

Right now the slider is set to 62.00 seconds, but our clock will convert it to 1 minute and 2 seconds.

So as soon as we cross 60 seconds, the clock will automatically add 1 minute like so:

59 seconds in After Effects Slider Past 60 seconds in After Effects Slider

Our clock is now starting to look like a real clock, however, we do need to add some zeros. Right now, the clock starts out with 0:0, but we need it to start out with 00:00 instead. So I need to add two 0’s on the left and two 0’s on the right.

Doesn't look like a clock just yet in After Effects

Step 13

To add two 0’s on each side we first need to create a function.

In this example, I will go back to our text editor and I am going to create a function.

I am going to say function addZero() and inside of the parenthesis I am going to say n, but it can be any variable you want.

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = Math.floor(slider/60);

function addZero(n){

}

min +”:”+sec

Step 14

Next, we are going to define our function with an if/else statement. I am going to say if variable n is less than 10 then I want to add a 0 to it by saying “0”+n. Then if it is greater than 10, I will say else return n.

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = Math.floor(slider/60);

function addZero(n){

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

}

min +”:”+sec

So in other words, if the number is less than 10, I want a 0 added to the front of my n. If it is greater than 10, I want it to just be n.

Step 15

Now I am going to add this function to both min and sec.

Let’s go back to the text editor again and type addZero in front of both min and sec like so:

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = Math.floor(slider/60);

function addZero(n){

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

}

addZero(min) +”:”+addZero(sec)

So as you can see, our clock is now working well.

Minutes and Seconds working together in After Effects

Now when I go past 60 seconds on the slider, the clock automatically adds 1 minute and everything is looking just right!

There are a few things I want to mention before we wrap this up. Right now, if I take our slider value into the negatives, watch what happens.

Negative value on after effects slider

You can tell that it is not looking great. So we are going to use an if/else statement again to fix this issue.

I will go back to the text editor and I will say if the slider is greater than 0, I want it to run this expression: addZero(min) +”:”+addZero(sec).  If the slider is less than 0, then I want it to be 00:00. So I am going to do a string and say “00:00”

slider = effect(“Slider Control”)(“Slider”);

sec = slider%60;
min = Math.floor(slider/60);

function addZero(n){
if(n<10) return “0” + n else return n;
}

if(slider > 0) {
addZero(min) +”:”+addZero(sec)+
} else {
“00:00”
}

In the negatives in After Effects slider

So right now the slider is set to -30 and the clock says 00:00, but as soon as we come out of the negatives, the clock starts working again.

Working clock in After Effects

We can also add expressions to our slider by ALT+CLICK (OPT+CLICK on a Mac) on the stopwatch icon.

Add expression to the slider in After Effects

To test this, let’s type time*2.

Crazy number in After Effects

As you can see, the number is kind of crazy. So we need to round it up. I am going to go back to the text editor and type the math.floor() again.

Math.floor(time*2)

math floor in After Effects

You can also have a starting point. You can say something like 1000 seconds minus Math.floor(time*2)

1000-Math.floor(time*2)

Countdown in After Effects

So it will start at 16:34 then it will count down. This can definitely be useful. I hope this post was helpful!

If you would like to learn more about Expression and how it can speed up your workflow in After Effects, check out my Learn After Effects Expressions Course.

Download Project File

About the author:

Sergei Prokhnevskiy

Sergei Prokhnevskiy is a Charlotte, NC based motion graphics designer, an online tutor, an entrepreneur, and Adobe MAX Master Speaker. Sergei is known for his quick and practical After Effects tips and tricks on YouTube, where he generated well over 6 million views on his tutorials. He has authored an online video course on After Effects Expressions and developed scripts for After Effects. He is also a former senior motion graphics designer at Fox Sports where he worked on graphics for NFL, Super Bowl, MLB, World Series, College Football, NASCAR, Women’s World Cup, and NASCAR Race Hub. He is very passionate about learning and teaching others.

5 FREE TIME-SAVING TOOLS

Over 100,000 downloads & counting!

These 5 After Effects tools will seriously speed up your workflow and save you hours of wasted time. More than that, they could be the difference between being able to complete a project on time or not!