Create a real-time digital clock in After Effects that updates every second using just an expression.
// Converts the current time into a digital clock format (HH:MM:SS)
// Apply this to a text layer
t = time; // current time in seconds
h = Math.floor(t/3600); // calculate hours
m = Math.floor((t%3600)/60); // calculate minutes
s = Math.floor(t%60); // calculate seconds
// Add leading zeros to single digits
hStr = h < 10 ? "0" + h : h;
mStr = m < 10 ? "0" + m : m;
sStr = s < 10 ? "0" + s : s;
hStr + ":" + mStr + ":" + sStr
Add this expression to the Source Text property of a Text Layer.
This expression takes the time
(which is how many seconds have passed in your comp) and:
Divides it by 3600 to get hours,
Takes the remainder and divides by 60 to get minutes,
And takes the final remainder as seconds.
It uses simple math (Math.floor
) to keep everything whole and readable. Then it adds a leading 0
if a number is less than 10—so you always get that classic "08:03:09" format.
Just copy the full expression code from the top of this page. Then Alt-click (or Option-click on Mac) the stopwatch on the property you want to animate. Paste the code into the editor and that's it. If you’re not sure which property to use, check the "Where to Apply" section above.
First, make sure your project is using the JavaScript engine (go to File > Project Settings > Expressions). Also double-check for missing characters, and see if the code requires parenting a layer. If so, there will be a comment in the code explaining what needs to be connected.
Take a look at the "How It Works" section on this page. It explains each part of the expression in plain language so you can understand how everything works together.
Yes, absolutely. Most expressions include easy-to-edit variables near the top and comments that guide you on what to change. You can also link sliders or checkboxes using Expression Controls if you want more control in the timeline.
Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.
In most cases, yes. These expressions are designed to adapt to your comp’s resolution and frame rate. If anything specific needs adjusting, it’ll be noted in the code or in the "How It Works" section.
Explore more expressions in this category