• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit
• Football Clock

# Football Clock

Explorer ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

Hi (again) - After Effects CS6

I need to create a clock in After Effects that runs the whole length of a football match (45 mins each half).

Looking at code in a template I brought - I have this expression:

countspeed = 1;

clockStart = 0;

function times(n){

if (n < 10) return "0" + n else return "" + n

}

clockTime = clockStart +countspeed*(time - inPoint);

if (clockTime < 0){

minus = "-";

clockTime = -clockTime;

}else{

minus = "";

}

t = Math.floor(clockTime);

h = Math.floor(t/3600);

min = Math.floor((t%3600)/60);

sec = Math.floor(t%60);

ms = clockTime.toFixed(3).substr(-3);

times(min) + ":" + times(sec) + ""

Now I worked out that by changing the 'clockStart = 0;' to = 2700, I have a 2nd half which starts at 45 mins, which is what I want.

But is there a way to show that when a match gets to 45 mins (or 90 mins in 2nd half) that instead of it going to 45.01.... it shows 45.00 +0.01, 45.00 +0.02 (as technically 46.00 is in the 2nd half)

Thanks for looking and any potential help you can provide

Lee

TOPICS
Expressions

Views

1.3K

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## 1 Correct answer

Explorer , May 04, 2015 May 04, 2015

Hi fcvideo,

you need to understand to code you type in, check this

Lesson06 – Counter and Text Formatting | AExpr Breakdown

min = Math.floor((t%3600)/60);

this part resets the minute counter every 60 minutes

modulo is like a loop maker, every 3600 seconds, it resets the value to 0, this should do the trick:

min = Math.floor(t/60);

6 Replies 6
LEGEND ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

Simply use a second layer and some manually typed text. I honestly don't get why people always want to do such a simple thing the hard way with expressions when they don't understand them.

Mylenium

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

That's actually a good call - didn't even consider that.

Just 1 last question then - is there a way to keep the minutes from converting to hours - ie 65 mins = 65 not 1 hour 5 mins

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

Hi fcvideo,

you need to understand to code you type in, check this

Lesson06 – Counter and Text Formatting | AExpr Breakdown

min = Math.floor((t%3600)/60);

this part resets the minute counter every 60 minutes

modulo is like a loop maker, every 3600 seconds, it resets the value to 0, this should do the trick:

min = Math.floor(t/60);

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
May 08, 2015 May 08, 2015

Copy link to clipboard

Copied

If you don't like to write or modify expressions code, you can also easily generate counters with Source Text Bundle of iExpressions.

iExpressions supports counters for Time, Dates and simple Numbers and is both simple and flexible in formatting those.

If you want 65 minutes to be shown as 65 minutes instead of 1 hour and 5 minutes, simply use the Counter Numbers instead of the Counter Time expression.

See this tutorial for an overview of creating counters with iExpressions.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 14, 2024 May 14, 2024

Copy link to clipboard

Copied

Hello Lee,

I tackled a similar issue while working on my website, tiroalpalo.co. To achieve the effect you're looking for, where the clock displays "45.00 +0.01" instead of "46.00" at the 45-minute mark, you can modify the existing code with a conditional statement that checks for this specific time interval.

Here’s an adjusted version of your script that implements this:

countspeed = 1;
clockStart = 0;

function times(n) {
if (n < 10) return "0" + n; else return "" + n;
}

clockTime = clockStart + countspeed * (time - inPoint);
if (clockTime < 0) {
minus = "-";
clockTime = -clockTime;
} else {
minus = "";
}

t = Math.floor(clockTime);
h = Math.floor(t / 3600);
min = Math.floor((t % 3600) / 60);
sec = Math.floor(t % 60);
ms = clockTime.toFixed(3).substr(-3);

// New condition to check and format the time at 45 mins and 90 mins
if (min === 45 && h === 0 || min === 45 && h === 1) {
return times(min) + ":" + "00 +" + ms;
} else {
return times(min) + ":" + times(sec);
}

This script will now display the milliseconds incrementing from "00" when reaching 45 or 90 minutes, which matches the format you desired. I implemented this approach on my website tiroalpalo, and it's working smoothly. I hope this helps you as well!

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 15, 2024 May 15, 2024

Copy link to clipboard

Copied

LATEST

Hi Lee,

You can achieve the desired effect by modifying your expression to show the extra time separately once it reaches 45 minutes or 90 minutes. Here's an updated version of your expression:

countspeed = 1;
clockStart = 0;

function times(n){
if (n < 10) return "0" + n;
else return "" + n;
}

clockTime = clockStart + countspeed * (time - inPoint);

if (clockTime < 0){
minus = "-";
clockTime = -clockTime;
} else {
minus = "";
}

t = Math.floor(clockTime);
h = Math.floor(t / 3600);
min = Math.floor((t % 3600) / 60);
sec = Math.floor(t % 60);
ms = clockTime.toFixed(3).substr(-3);

if (min >= 45) {
extraTime = clockTime - 45 * 60;
min = 45;
sec = Math.floor(extraTime);
ms = extraTime.toFixed(3).substr(-3);
extraTimeString = "+" + Math.floor(extraTime / 60) + ":" + times(sec % 60) + ":" + ms;
times(min) + ":00" + extraTimeString;
} else {
times(min) + ":" + times(sec);
}

This expression will display the extra time separately once it reaches 45 minutes or 90 minutes. You will see something like "45:00 +0:01.000", indicating the extra time added after 45 minutes.

Best regards,

Hamza

For more details, Visit