matt hackmann -> web developer

Display Time Code in After Effects with Expressions

Posted on in after effects programming

Whilst working on my current video project, I came across a need to display the current time code. Expressions are the answer, of course, so I came up with this.

Code: javascript
  1. txt = "";
  2. frames = timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false);
  3. f = frames % 30;
  4. s = Math.floor(frames / 30);
  5. m = Math.floor(s / 60) % 60; s %= 60;
  6. h = Math.floor(m / 60);
  7. if (f < 10) f = "0" + f;
  8. if (s < 10) s = "0" + s;
  9. if (m < 10) m = "0" + m;
  10. if (h < 10) h = "0" + h;
  11. txt = h + ":" + m + ":" + s + ";" + f;
  12. txt

Simply attach this expression to the Source Text property of a text layer and viola!