 5 Minute Countdown
•    
I'm trying to make a countdown which counts down from 5:00 Minutes to 0:00.
I want it to work in actual seconds, like a normal clock.
I've tryed Effect/Text/Numbers.
I've messed with all the things for weeks and can't figure it out.
Searched the internet and still can't find what i need.
Can anyone help me?
Tutorial? Anything?
Thanks,
Stephen
    
•      Re: 5 Minute Countdown by Dan Ebberts on Jul 21, 2008 at 9:26:41 pm 
Try pasting this into the source text property of a text layer:
rate = 1;
clockStart = 300;
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)
Dan
    
•      Re: 5 Minute Countdown by Stephen Burton on Jul 22, 2008 at 12:08:18 am 
What about for a 2 minute one?
WHat would i change?
that one worked great! THANKS!
    
•      Re: 5 Minute Countdown by Dan Ebberts on Jul 22, 2008 at 12:29:19 am 
Just change the 300 to 120 (the duration is in seconds).
Dan
    
•    
Thanks Dan.
You've been incredibly helpful.
Exactly what i needed to know!!
You Rock!
    
•      Re: 5 Minute Countdown by Kjell Nygren on Aug 2, 2008 at 4:54:48 pm 
I've been trying to get this expression to show milliseconds and I just can't get it to work. I've tried some other expressions that do it, but they all seem to break. I have to create a 45min 30sec countdown, but I want it to show milliseconds as well.
Please help
Thanks,
Kjell
    
•      Re: 5 Minute Countdown by Dan Ebberts on Aug 2, 2008 at 5:28:41 pm 
Try this:
rate = 1;
clockStart = 2730;
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);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.toFixed(3).substr(3);
sign + padZero(min) + ":" + padZero(sec) + "." + ms
Dan
    
•      Re: 5 Minute Countdown by John Barata on Jan 20, 2009 at 7:36:18 pm 
Hi Dan,
Great post. I tried it out and perfect. The only problem is that is doesn't work for what I need and I can't figure out what to change.
I need a clock that counts up normally that shows hr:min:sec starting at whatever time.
Is there a simple fix to make this work?
    
•      Re: 5 Minute Countdown by Dan Ebberts on Jan 20, 2009 at 9:00:19 pm 
This source text expression should work. Just set the clockStart variable to the start time (in seconds).
rate = 1;
clockStart = 0;
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);
sign + padZero(hr) + ":" + padZero(min) + ":" + padZero(sec)
Dan
    
•      Re: 5 Minute Countdown by John Barata on Jan 21, 2009 at 4:53:27 pm 
Thanks for your help Dan but before I read your post I stumbled across this one
addedSec = thisComp.layer("Controller").effect("Seconds")("Slider");
addedMin = thisComp.layer("Controller").effect("Minutes")("Slider")*60;
addedHr = thisComp.layer("Controller").effect("Hours")("Slider")*3600;
addedTime = addedSec + addedMin + addedHr;
sec = Math.floor(time + addedTime) * thisComp.layer("Controller").effect("Time Multiplier")("Slider");
minvar = Math.floor(sec/60);
hrvar = Math.floor(sec/3600);
sechrvar = Math.floor(sec  (3600*hrvar));
minhrvar = Math.floor(sechrvar/60);
if(sec<0){
"Err: Negative Time"
}else{
if ((sec  10) < 0) {
":0" + sec
} else {
if ((sec  60) < 0) {
":" + sec
}else{
if (((sec/60)>1) && ((sec  minvar*60)<10) && (sec<3600)) {
(minvar) + ":0" + (sec  minvar*60)
}else{
if ((sec  60) < 0) {
":" + sec
}else{
if ((sec/60) == 1) {
(minvar) + ":00"
}else{
if (((sec/60)>1) && ((sec  minvar*60)>=10) && (sec<3600)) {
(minvar) + ":" + (sec  minvar*60)
}else{
if((sec  3600*hrvar) == 0){
(hrvar) + ":00:00"
}else{
if(((sec  3600) > 0) && ((sec  (3600*hrvar)  (minhrvar*60)< 10)) && (minhrvar<10)){
(hrvar) + ":0" + minhrvar + ":0" + (sechrvar  minhrvar*60)
}else{
if(((sec  3600) > 0) && ((sec  (3600*hrvar)  (minhrvar*60)) >=10) && (minhrvar < 10)){
(hrvar) + ":0" + minhrvar + ":" + (sechrvar  minhrvar*60)
}else{
if(((sec  3600) > 0) && ((sec  (3600*hrvar)  (minhrvar*60)) < 10) && (minhrvar >= 10)){
(hrvar) + ":" + minhrvar + ":0" + (sechrvar  minhrvar*60)
}else{
if(((sec  3600) > 0) && ((sec  (3600*hrvar)  (minhrvar*60)) >=10) && (minhrvar >= 10)){
(hrvar) + ":" + minhrvar + ":" + (sechrvar  minhrvar*60)
}else{
sec}}}}}}}}}}}}
I can't remember if you had written it on another forum but it worked great.
But once again thank you for your help either way. It's great to know that there are people out there always willing to help.
Cheers
    
•    
This is exactly what I need but unfortunatelly when I paste it in expressions place it said that there is a mistake on line 6 and the expression is disabled
    
•      Re: 5 Minute Countdown by Dan Ebberts on Oct 8, 2009 at 5:40:44 pm 
Which property did you paste it into, and what was the exact error message?
Dan
    
•      Re: 5 Minute Countdown by Peta Kyle on Jan 20, 2010 at 5:30:49 pm 
I'm having the same issue with an error on line six. Did anyone ever find out what the problem was?
    
•      Re: 5 Minute Countdown by Kay Rinne on Jun 9, 2011 at 3:04:52 pm 
I am getting the Line 6 error as well.
After Effects warning: Expected: )
Expression disabled
Error occurred at Line 6.
Comp: 'Comp 2'
Layer: 1 ('5:00')
Proprty: 'Positon'
Obviously its looking to close a parentheses somewhere?
line 6 should correspond to the if statement and the "n" var opens but does not close?
using this code:
rate = 1;
clockStart = 300;
function padZero(n){
if (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)
    
•      Re: 5 Minute Countdown by Dan Ebberts on Jun 9, 2011 at 3:36:15 pm 
Somewhere along the line the padZero function got messed up, probably because of the "<".
It should look like this:
function padZero(n){
if (n < 10) return "0" + n else return "" + n;
}
Dan
    
•      Re: 5 Minute Countdown by Kay Rinne on Jun 10, 2011 at 5:02:56 pm 
thanks that helped!
    
•      Re: 5 Minute Countdown by Karl pouillot on Nov 7, 2011 at 11:26:46 pm 
Bonsoir,
Merci pour ton aide tout d'abord. After Effects est loin d'être facile à prendre en main. Et c'est bien la première fois que je vois un logiciel comme celuici qui demande de savoir programmer!
Bref, j'aurais besoin à nouveau de tes lumières...
Cette expression ci dessous marche très bien mais j'aimerais rajouter les millisecondes dans le décompte, histoire d'avoir un truc un peu plus dynamique.
Tu crois que tu pourrais me filer un coup de pouce?
Merci d'avance!
Bonne nuit
rate = 1;
clockStart = 1440;
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);
mil = Math.floor(t%500)
min + ":" + padZero(sec)
    
•      Re: 5 Minute Countdown by Dan Ebberts on Nov 7, 2011 at 11:53:58 pm 
S'il vous plaît, essayez ceci:
rate = 1;
clockStart = 1440;
function padZero(n){
return ((n < 10) ? "0" : "") + 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) + clockTime.toFixed(3).substr(4)
Dan
    
•      Re: 5 Minute Countdown by Karl pouillot on Nov 8, 2011 at 9:16:37 pm 
Thank you for your help.
But i've done a mistake. I need tenth second, not thousandth second.
And there is an another problem on the digital display. There is only "on point" between the second and the thousandth second but we need two points like what we have between minute and second.
Could you help for that?
Thank you.
PS : Sorry for my english, i m a little bit rusty...
    
•      Re: 5 Minute Countdown by Dan Ebberts on Nov 8, 2011 at 11:58:23 pm 
Try this:
rate = 1;
clockStart = 1440;
function padZero(n){
return ((n < 10) ? "0" : "") + 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) + ":" + clockTime.toFixed(1).substr(1)
Dan
    
•      Re: 5 Minute Countdown by Karl pouillot on Nov 9, 2011 at 12:22:33 am 
It's perfect but do you know how i could save correctly this composition to read it on quicktime or VLC?
As soon as i want to save it, the final composition run during 30 sec and stop itself. It doesn t make sense, the countdown last 24 minutes. Any solution?
Thank you!
    
•      Re: 5 Minute Countdown by Dan Ebberts on Nov 9, 2011 at 3:12:39 am 
If your comp is long enough, it should count down the whole 24 minutes. Are you possibly looking at a preview? You'll need to render a movie to see the whole thing: Composition > Make Movie...
Sorry if you already knew that.
Dan
    
•      Re: 5 Minute Countdown by Karl pouillot on Nov 9, 2011 at 7:47:39 pm 
The countdown only to last 30 sec. I don t know how make it run 24 minutes...
After 23:30:04, it stop. That's weird, isn'it?
    
•      Re: 5 Minute Countdown by Dan Ebberts on Nov 9, 2011 at 7:51:46 pm 
Seems weird to me.
Dan
    
•      Re: 5 Minute Countdown by Karl pouillot on Nov 9, 2011 at 8:00:52 pm 
Could i send you the file to take a quick look on it?
    
• •      Re: 5 Minute Countdown by jose l garcia on May 24, 2012 at 6:42:52 pm 
is not posible to pause the time and resume it? will be great if is possible to add some kind of key into the timeline to pause and again resume it.
    
•      Re: 5 Minute Countdown by Akira Jun on May 24, 2012 at 8:34:37 pm 
I can use this expression with any frame rate like 242960 or the code just follow the comp frame rate by itself?
Thanks.
rate = 1;
clockStart = 300;
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)
    
•      Re: 5 Minute Countdown by Dan Ebberts on May 24, 2012 at 9:01:54 pm 
You set the countdown rate in the first line. At 1 it counts at regular comp speed, at 2 it would be twice as fast, etc. Does that answer your question?
Dan
    
•      Re: 5 Minute Countdown by Akira Jun on May 24, 2012 at 10:53:34 pm 
I think i got it.
If i keep 1 the expression will work as the same a comp frame rate is.
I have another question wich is the same one above of Jose.
Using this expression to a "fight" scene where the judge sometimes stop and the counter must stop to then when he start will continue the same time position.
Is possible to add somes keys into the timeline to pause and resume?
Ex:
5:00 ~ 4:10 run
4:10~3:40 stop
3:40~2:20 run
2:20~1:30 stop
1:30~0:00 run
Regards.
Jun
rate = 1; clockStart = 300; 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)
    
•      Re: 5 Minute Countdown by Dan Ebberts on May 25, 2012 at 1:08:26 am 
You would need a more complex expression. Here's one that uses a checkbox control on the text layer to drive the count down. The count only proceeds when the checkbox is in the "on" state.
p = effect("Checkbox Control")("Checkbox");
accum = 0;
ct = inPoint;
cv = p.valueAtTime(inPoint);
for (i = 1; i <= p.numKeys; i++){
kt = p.key(i).time;
if (kt <= inPoint) continue;
if (kt >= time) break;
accum += cv*(kt  ct);
cv = p.key(i).value;
ct = kt;
}
accum += cv*(timect);
rate = 1;
clockStart = 1440;
function padZero(n){
return ((n < 10) ? "0" : "") + n;
}
clockTime = Math.max(clockStart + rate*accum,0);
t = Math.floor(clockTime);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60); min + ":" + padZero(sec) + ":" + Math.floor((clockTime%1)*10)
Dan
    
•      Re: 5 Minute Countdown by Akira Jun on May 25, 2012 at 3:03:48 am 
Wow...
Just wonderfull!!
Thank you!!
"Arigatou Gozaimashita!!"
Jun
    
•      Re: 5 Minute Countdown by Karl pouillot on Nov 9, 2011 at 7:54:12 pm 
In fact, the countdown restart from the beginning... It run from 24:00:00 to 23:30:04 and restart from 24:00:00 after 30 sec...
I need a really countdown of 24minutes and not 30 sec +S
Please, help!
    
•    
Great one Dan, thx
Is there a way to have this countdown display in absolute seconds (300, 299, 298...) rather then in a clock format (5:00, 4:59..)?
    
•      Re: 5 Minute Countdown by Dan Ebberts on Jan 31, 2009 at 9:05:50 pm 
Try this:
rate = 1;
clockStart = 300;
clockTime = Math.max(clockStart + rate*(time  inPoint),0);
Math.ceil(clockTime)
Dan
    
•      Re: 5 Minute Countdown by Tina Ferguson on Feb 6, 2009 at 7:07:56 pm 
This is great. Thanks for doing this.
I am curious if there is a way to change the font type of the numbers using this method.
    
•      Re: 5 Minute Countdown by Dan Ebberts on Feb 6, 2009 at 8:23:59 pm 
No, expression don't have access to font info.
Dan
    
•      Re: 5 Minute Countdown by michael Nguyen on Nov 30, 2009 at 10:29:59 pm 
hi,
I tried using this code but it seems its limited to an hour. i am trying to do a 2 hour countdown. is there something else i need to change besides the seconds?
mike
    
•      Re: 5 Minute Countdown by Dan Ebberts on Nov 30, 2009 at 11:14:27 pm 
There's a lot of code in this thread. To which are you refering?
Dan
    
•      Re: 5 Minute Countdown by michael Nguyen on Nov 30, 2009 at 11:17:23 pm 
this one
rate = 1;
clockStart = 300;
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)
    
•      Re: 5 Minute Countdown by Dan Ebberts on Nov 30, 2009 at 11:31:07 pm 
Play around with this one:
rate = 1;
clockStart = 7200;
function padZero(n){
if (n < 10) return "0" + n else return "" + n
}
clockTime = Math.max(clockStart + rate*(time  inPoint),0);
t = Math.ceil(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
padZero(hr) + ":" + padZero(min) + ":" + padZero(sec)
Dan
    
•    
Hi,
First of all thank you very much Dan for this thread it's really very helpful for the expression dummies like me. :)
I am doing a countdown for 5:00 and am having an error message on line 6 like 2 other people.
I am using your first expression: (on a text layer on which i wrote 5:00)
rate = 1;
clockStart = 300;
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)
I can't see what the problem is.
rate = 1;
clockStart = 300;
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)
    
•      Re: 5 Minute Countdown by Steven Knight on Nov 26, 2010 at 3:44:13 am 
Hi Dan,
Thank you for these script tips.
One problem I'm come across is the countdown eventually falling out of synch; apparently due to the 23.976 frame rate  it works like a charm at 24 fps.
Any help would be greatly appreciated.
Thank you for your time.
Cheers.
S.J.
rate = 1;
clockStart = 3600;
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%3601)/60);
sec = Math.floor(t%60);
padZero(min) + ":" + padZero(sec)
    
•    
Hi code works great but I am wondering if their is away to get rid of the leading number when they turn to zero.
Chad
    
•      Re: 5 Minute Countdown by Dan Ebberts on Aug 28, 2012 at 10:16:41 pm 
I'm not sure which version you're talking about, but to eliminate leading zeros you would eliminate the call to padZero():
rate = 1;
clockStart = 7200;
function padZero(n){
if (n < 10) return "0" + n else return "" + n
}
clockTime = Math.max(clockStart + rate*(time  inPoint),0);
t = Math.ceil(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
"" + hr + ":" + min + ":" + padZero(sec)
Dan
    
•    
Hi Dan I am confused. Here is the code I am using. I want I five minute countdown. But when it gets down to just seconds I dont want the zeros to shows.
rate = 1;
clockStart = 300;
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)
Chad
    
•      Re: 5 Minute Countdown by Dan Ebberts on Aug 29, 2012 at 2:08:16 am 
I'm still not sure exactly what you're after, but try changing the last line to this:
(min > 0 ? min : "") + ":" + padZero(sec)
and if that's not it, try this:
min > 0 ? min + ":" + padZero(sec) : sec
Dan
    
•    
That a little closer. What I want it to do is somthing like this count down from 5:00, 5:59,5:58.....4:00...3:00...1:00, 59, 58 ...10, 9, 8, 7 ... 1, 0
Sorry for all the confusion
Chad
    
•      Re: 5 Minute Countdown by Dan Ebberts on Aug 29, 2012 at 4:27:02 am 
Now I'm confused. Isn't that what the second variation from my previous post does?
Dan
    
•    
The last post does do that except when it gets down to sec the semi colon is still showing. The previous one were I get ride of the call to padZero does count down in sec but does not show the minutes.
Thanks for all the help.
Chad
    
•      Re: 5 Minute Countdown by Ruben Gomez on Jun 16, 2015 at 11:14:31 am 
Hi Dan,
That script was very helpful.... Is there any way in the script that I can start the countdown after couple of seconds....
rate = 1;
clockStart = 300;
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)
    
•      Re: 5 Minute Countdown by Dan Ebberts on Jun 16, 2015 at 7:56:27 pm 
This gives a twosecond delay:
rate = 1;
clockStart = 300;
delay = 2;
function padZero(n){
if (n < 10) return "0" + n else return "" + n
}
t = Math.max(time  delay,0);
clockTime = Math.max(clockStart + rate*(t  inPoint),0);
t = Math.floor(clockTime);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
min + ":" + padZero(sec)
Dan
    
•      Re: 5 Minute Countdown by Ruben Gomez on Jun 16, 2015 at 8:22:45 pm 
Thanks Dan,
That worked :)
    
•      Re: 5 Minute Countdown by adam fram on Oct 29, 2015 at 10:16:45 pm 
Dan,
The countdown/up script on your website is super helpful and very customizable so thank you for that genius piece of code.
I noticed that the counter seems to round in the wrong direction when counting. Here's an example of it counting down: 59.02, 59.01, 58.00, 58.99, 58.98
Is there a simple code solution related to the padding that I can use for this?
Thanks!
Adam Fram
adamfram.com
rate = 1;
clockStart = 600.00;
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(2).substr(2);
padZero(min) + ":" + padZero(sec) + "." + ms
    
•      Re: 5 Minute Countdown by Dan Ebberts on Oct 30, 2015 at 2:51:43 am 
This should work better:
rate = 1;
clockStart = 600.00;
function padZero(n){
if (n < 10) return "0" + n else return "" + n
}
clockTime = clockStart + rate*(time  inPoint);
t = clockTime.toFixed(2);
ms = t.substr(2);
t = parseInt(t,10);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
padZero(min) + ":" + padZero(sec) + "." + ms
Dan
    
•      Re: 5 Minute Countdown by adam fram on Oct 30, 2015 at 5:30:15 pm 
Perfect. Thanks Dan, you rock!

Adam Fram
adamfram.com
    
 
