Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to create clock display

New Here ,
Jan 16, 2023 Jan 16, 2023

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!

 

 

TOPICS
Scripting
412
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2023 Jan 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-java...

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2023 Jan 16, 2023
LATEST

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());
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines