• | **Clock**
on Mar 5, 2010 at 8:51:09 am |

Hello I was trying to find an expression similar to a frame counter, but where I could start it at a specific number and count on like a clock. Starting at 21:19:20:02 for example so hours/minutes/seconds/frames.

Thanks

• | **Re: Clock** on Mar 5, 2010 at 11:28:08 am |

Hello

Oops I just found all of the other posts and links to motionscript.com

Thanks

• | **Elegant way (but not bullet proof)** on Mar 6, 2010 at 10:05:01 am |

There are two ways to resolve the clock:

The first is using timeToTimecode (a built-in AE expression method)

Problem is it is bounded by 3 hours, each time above 3 hours will show 3:00:00:00

But the code is much simpler

The second option will be in the next message

`startH = 1; // 21 will overflow`

startM = 19;

startS = 20;

startF = 02;

timeShift = startH * 3600 + startM * 60 + startS + startF * thisComp.frameDuration;

framesPerSec = 1/thisComp.frameDuration;

timeToTimecode(t = time + timeShift, timecodeBase = framesPerSec, isDuration = false)

• | **Less elegant but more robust** on Mar 6, 2010 at 10:06:42 am |

This code will work in all cases, except overflowing of the Hours

in case you'll get to 23:59:59:24 next frame will be 24:00:00:00

Enjoy

`separator = ":"`

// offset

startH = 21;

startM = 19;

startS = 20;

startF = 02;

// calculate current time in H:M:S:F format

framesPerSec = 1/thisComp.frameDuration;

F = Math.round((time % 1) * framesPerSec);

timeRemainder = Math.floor(time);

S = timeRemainder % 60;

timeRemainder = timeRemainder - S;

timeRemainder = timeRemainder / 60;

M = timeRemainder % 60;

timeRemainder = timeRemainder - M;

timeRemainder = timeRemainder / 60;

H = timeRemainder; // there's no handling if H > 24...

// add offset

F = F + startF

S = S + startS

M = M + startM

H = H + startH

// check overflowing

if (F >= framesPerSec)

{

F = F - framesPerSec;

S = S + 1;

}

if (S >= 60)

{

S = S - 60;

M = M + 1;

}

if (M >= 60)

{

M = M - 60;

H = H + 1;

}

// add "0" to the beginning of the number if it is smaller than 10

StrF = (F < 10 ? "0" : "") + F;

StrS = (S < 10 ? "0" : "") + S;

StrM = (M < 10 ? "0" : "") + M;

StrH = (H < 10 ? "0" : "") + H;

"" + StrH + separator + StrM + separator + StrS + separator + StrF