FORUMS: list search recent posts

# How would I add Milliseconds to this expression?

FAQ   •   VIEW ALL
 How would I add Milliseconds to this expression? on May 26, 2014 at 5:54:11 am

Hi Guys,

Just wondering how I would add milliseconds to this expression?

rate = -1;
clockStart = 388;

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);

Thanks

Jackson

 Re: How would I add Milliseconds to this expression?on May 26, 2014 at 6:10:25 am

At what frame rate do you need to deliver your finished work? If it's one of the standard rates, whether you have the ability to add or delete a few milliseconds or not is irrelevant.

Dave LaRonde
Promotion Producer
KGAN (CBS) & KFXA (Fox) Cedar Rapids, IA

 Re: How would I add Milliseconds to this expression?on May 26, 2014 at 6:14:29 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

 Re: How would I add Milliseconds to this expression?on May 26, 2014 at 1:14:31 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

 Re: How would I add Milliseconds to this expression?on May 26, 2014 at 1:26:45 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
Motion Graphics, Widescreen Events, Presentation Design, and Consulting