Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects How would I add Milliseconds to this expression?

  • How would I add Milliseconds to this expression?

    Posted by Jackson Redshaw on May 26, 2014 at 5:54 am

    Hi Guys,

    Just wondering how I would add milliseconds to this expression?

    rate = -1;
    clockStart = 388;

    function padZero(n){
    if (n < 10) return “0” + n else return “” + n
    }

    clockTime = Math.max(clockStart + rate*(time – inPoint),0);

    t = Math.floor(clockTime);
    min = Math.floor((t%3600)/60);
    sec = Math.floor(t%60);

    min + “:” + padZero(sec)

    Thanks

    Jackson
    http://www.youtube.com/MITLRproductions

    Jackson Redshaw replied 11 years, 11 months ago 2 Members · 4 Replies
  • 4 Replies
  • Jackson Redshaw

    May 26, 2014 at 6:14 am

    Hi Dave,

    The frame rate is 25. At the moment, only the minute/s and second/s are displayed on the screen

    Thanks

    Jackson
    http://www.youtube.com/MITLRproductions

  • Jackson Redshaw

    May 26, 2014 at 1:14 pm

    I think you misunderstood the question, entirely my fault though.

    The expression is generating a countdown clock on the screen. But only the minute/s and seconds are displayed.

    Thnaks

    Jackson
    http://www.youtube.com/MITLRproductions

  • Walter Soyka

    May 26, 2014 at 1:26 pm

    rate = -1;
    clockStart = 388;

    function padZero(n){
    if (n < 10) return "0" + n else return "" + n
    }

    clockTime = Math.max(clockStart + rate*(time - inPoint),0);

    t = Math.floor(clockTime);
    min = Math.floor((t%3600)/60);
    sec = Math.floor(t%60);
    milliseconds = clockTime.toFixed(3).split(".")[1];

    min + ":" + padZero(sec) + "." + milliseconds;

    The magic happens here:
    milliseconds = clockTime.toFixed(3).split(".")[1];

    Here’s a translation. toFixed() is a method that converts a number to a string with a fixed number of decimal places (in this use above, 3). It will pad with zeroes as necessary to maintain this fixed number.

    split() is a method which splits a string into an array of substrings when given a separator. In this case, the separator is a period. For the string “0.123.456”, split(“.”) yields this array of strings: [“0″,”123″,”456”]. We use array indices to access a specific substring.

    In plain English, the above line says convert the clock time to a string including 3 decimal places, then take only the digits after the decimal point and call them “milliseconds.”

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • Jackson Redshaw

    May 26, 2014 at 1:28 pm

    Thanks so much Walter. Worked Perfectly!

    Jackson
    http://www.youtube.com/MITLRproductions

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy