Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Clock Expression adapting Dan Ebberts code

  • Clock Expression adapting Dan Ebberts code

    Posted by Jessica Ashley on May 20, 2012 at 9:16 pm

    hello,

    ive been trying to use different versions of Dan Ebberts clock expression but cant seem to get what I need. Please help.

    I need 12-hour time, starting at a specific time, ending at a specific time. example 7:34:24 am and ending 11:41:24 pm

    im currently using this with a slider, to get the start and end time

    —-

    rate = 0;
    clockStart = effect(“Slider Control”)(“Slider”);

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

    clockTime = clockStart + rate*(time – inPoint);

    if (clockTime < 0){
    sign = “-“;
    clockTime = -clockTime;
    }else{
    sign = “”;
    }

    t = Math.floor(clockTime);
    hr = Math.floor(t/3600);
    min = Math.floor((t%3600)/60);
    sec = Math.floor(t%60);
    ms = clockTime.toFixed(3).substr(-3);
    sign + padZero(hr) + “:” + padZero(min) + “:” + padZero(sec)

    —–

    and the slider moves between the time codes. The time needs to speed up and slow down so I have keyframed this with the slider. I add the am and pm manually.

    The problem im having is its 24 time. i need this code as 12-hour time.

    Can someone help?

    Thanks in advance, j

    Robert Sztabralowski replied 11 years, 7 months ago 4 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    May 20, 2012 at 9:43 pm

    I haven’t test this, but I would think you could change to a 12 hour clock like this:

    hr = Math.floor(t/3600)%12;
    if (hr == 0) hr = 12;

    Dan

  • Jessica Ashley

    May 20, 2012 at 10:02 pm

    Hi Dan,

    That works perfectly thank you!!!

    One more question, is there any way to get rid of the leading 0 in the hours column? so the number looks like:
    7:24:11 an opposed to 07:24:11. Or will this tamper too much with “:” and then the numbers will jump all over the place?

    Thank you!!

  • Dan Ebberts

    May 20, 2012 at 10:18 pm

    If it’s right justified, I would think changing the last line to this would work:

    sign + hr + “:” + padZero(min) + “:” + padZero(sec)

    Dan

  • Jessica Ashley

    May 20, 2012 at 10:43 pm

    its working almost perfectly. thank you so much!

    One more query .. not sure if this is possible but whenever the mins or sec reach the number 11, the spacing of the ":" moves. It only happens on 11. Im using arial bold (I have to use this font). Currently justified right. Is there any way to fix this?

  • Dan Ebberts

    May 20, 2012 at 10:54 pm

    Sorry–I can’t think of any way to control that.

    Dan

  • Jessica Ashley

    May 20, 2012 at 11:02 pm

    that's ok - you have helped me so much. Thank you!!!1!

  • Dan Fredley

    May 24, 2012 at 12:28 am

    Some fonts do that for some reason–I usually switch fonts, but since you’re stuck with Arial Bold, you could try breaking out each “number set” on their own and have the colons as static text layers separate from the expression.

    So you’d have the expression end with only padZero(hr) on one text layer, then padZero(min) on another text layer, etc.

    The numbers might still jump around a bit, but at least the symbols don’t move.

    –I’d keep the original text layer as a guide to help you manually place the numbers and colons correctly then parent them to a null so you can move them together or precomp them.

    Dan Fredley

  • Robert Sztabralowski

    September 22, 2014 at 12:19 pm

    Maybe You can just mask out the zero in the front…. without messing up with expression…

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