ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Creating a Ticking Down Timer

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ben Kahane-RapportCreating a Ticking Down Timer
by on Feb 1, 2014 at 5:49:34 am

Hey Creative Cows,
I'm trying to make a timer that ticks down from 97 years in real time. Ideally, it would be:
years:months:days:hours:minutes:seconds
Is this doable?

The best I've got is the following, which has the first value going down every second, instead of the last:

function decrementNumber(num, leading, modulus) {
num="" + Math.floor(num-((timefactor % 1) *num)) % modulus;
while (num.length < leading) num='0'+num;
return num;

}

// Variables
years=93;
months=12;
days=364;
hours=24*days;
minutes=60*hours;
seconds=60*minutes;
timefactor=time;

// Calculations
years="" + Math.floor(years-timefactor);
while (years.length < 2) years='0' + years;

months=decrementNumber(months,2, 12 );
days=decrementNumber(days,2, 28 );
hours=decrementNumber(hours,2, 24 );
minutes=decrementNumber(minutes,2, 60 );
seconds=decrementNumber(minutes,2, 60 );

counter="" + years + ":" + months + ":" + days + ":" + hours + ":" + minutes +":" + seconds


Any help would be much appreciated! Thanks!


Return to posts index

Declan SmithRe: Creating a Ticking Down Timer
by on Feb 1, 2014 at 11:43:58 am

Hi Ben,

I thought this looked familiar. My modified code is below which should meet your new requirement. This will start the counter at 97 years and count down in real time backwards. You can start the countdown by changing the variable 'startDate' .

Hope this is what you are looking for:

function pad(num, leading) {
num="" + num;
while (num.length < leading) num='0'+num;
return num;
}
// Variables
startDate = new Date("01/01/2067 00:00", ) ;

date = new Date(startDate.getTime()-(time*1000));
years=pad(date.getYear(date)-70,2);
months=pad(date.getMonth()+1,2);
days=pad(date.getDate(),2);
hours=pad(date.getHours(),2);
minutes=pad(date.getMinutes(),2);
seconds=pad(date.getSeconds(),2);
counter="" + years + ":" + months + ":" + days + ":" + hours + ":" + minutes +":" + seconds

Declan Smith
http://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

"it's either binary or it's not"


Return to posts index

Ben Kahane-RapportRe: Creating a Ticking Down Timer
by on Feb 1, 2014 at 9:29:14 pm

Thank you so much! Your generosity is astounding :)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]