Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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-java...
Copy link to clipboard
Copied
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());