Timer Expression To Count Hours.
Copy link to clipboard
Copied
Hello people! I would like help with an expression on a timer that counts hours. After a search I found this expression:
t = Math.floor (time);
minut = Math.floor (t / 60);
second = t% 60;
if (minut <10)
{
if (second <10)
{
['0' + minut + ':' + '0' + second];
}
else
{
['0' + minut + ':' + second];
}
}
else
{
if (second <10)
{
[minut + ':' + '0' + second];
}
else
{
[minut + ':' + second];
}
}
This expression works well, the only problem is that it does not count hours correctly. After 59:59 the timer goes to 60:00 and not 1:00:00. How could this expression be adjusted to work in a way that counts hours? If possible, show two expressions, one in the 1:00:00 format and the other in the 01:00:00 format.
Thanks in advance!
Copy link to clipboard
Copied
Your expression is only going to count minutes.
The best option is probably Dan Ebberts Up Down Counter.
The article and the expression are pretty easy to understand.
Copy link to clipboard
Copied
Thank you! It helped a lot! Just one more doubt. Is it possible to make the text = outPoint time of the layer? Based on the expression I sent? For example: if the text layer is 03:30 in length, the text will be 03:30 and will remain in that number, without counting up or down, just remaining frozen in the time outPoint value of the layer, is it possible?
Copy link to clipboard
Copied
If you use the Expression Language>Global Menu in the timeline you'll find the time to timecode operator. If you subtract the outPoint from the inPoint property you get the total time of the current layer. "t" in the time to timecode operator is the time value. You can just do the calculation there. The result will be hours, minutes, seconds, and frames. By far the easiest way to eliminate hours or frames is to draw a mask on the text layer to hide those values. The duration option includes the last frame of the layer if set to true, but if it is set to false, the value reported does not include the time it would take to play the last frame. Your expression would look like this:
timeToTimecode(t = outPoint - inPoint, timecodeBase = 30, isDuration = true)
If the comp's frame rate was 23.976 then you would set the timecodeBase to that value so the frame numbers would be accurate. That's all there is to it.

