Skip to main content
Participant
January 16, 2023
Question

Trying to create clock display

  • January 16, 2023
  • 2 replies
  • 451 views

Hello! I am trying to create a clock display that display time as 00:00:00:00 (hours, minutes, seconds, milliseconds) and counts up using slider control. Here is what I have so far:

 

slider = effect("Slider Control")("Slider")

x = new Date(1970,0,1); x.setSeconds(slider);

x.setMilliseconds(slider % 1 * 100);

x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds() + ":" + x.getMilliseconds();

 

This displays 0.0.0.00 .

 

Thanks!

 

 

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
January 16, 2023

It works for me if you just add a function to pad the extra zero when necessary:

slider = effect("Slider Control")("Slider");
function pad(n){
  return (n < 10 ? "0" : "") + n;
}
x = new Date(1970,0,1); 
x.setSeconds(slider);
x.setMilliseconds(slider % 1 * 100);
pad(x.getHours()) + ":" + pad(x.getMinutes()) + ":" + pad(x.getSeconds()) + ":" + pad(x.getMilliseconds());
Mathias Moehl
Community Expert
Community Expert
January 16, 2023

if you own iExpression, this expression will be an easy solution:

https://mamoworld.com/after-effects-expression/counter-time

If you want to write your own expression and are looking for ways to add leading zeros to your numbers, see here: https://stackoverflow.com/questions/1127905/how-can-i-format-an-integer-to-a-specific-length-in-javascript

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects