Skip to main content
brandonb96942845
Inspiring
March 2, 2023
Answered

AE Expression for Current Time (as in time of day, not composition timecode)

  • March 2, 2023
  • 3 replies
  • 3081 views

I've found an expression that will pull today's date automatically, but now I want to do something like that with the time as well. (Literally just pull the current hour and minute from the system clock.)

 

All the search results I can find talk about the Time() expression as it relates to the current time in the composition; I know there's a way do to this through an effect but I'd really just like to add it to the SourceText of a layer if at all possible. (And for bonus points would be helpful to be able to format it as 24-hour time, with zeroes padding on the hours.)

 

I'm sure there's a way to do it but after several hours of searching I'm coming up emptyhanded. Would be very grateful for anyone's help on this!

This topic has been closed for replies.
Correct answer Dan Ebberts

Maybe something like this:

s = effect("Slider Control")("Slider");

function padZero(n){ return (n < 10 ? "0" : "") + n }

baseSec = s*3600;
t = baseSec + time - inPoint;

hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
padZero(hr) + ":" + padZero(min) + ":" + padZero(sec)

3 replies

Dan Ebberts
Community Expert
Community Expert
March 2, 2023

You could do something like this:

function padZero(n) { return (n < 10 ? "0" : "") + n}
D = new Date(Date(0));
padZero(D.getHours()) + ":" + padZero(D.getMinutes()) + ":" + padZero(D.getSeconds())

but it doesn't appear to update, so I don't know if it's of any use to you.

brandonb96942845
Inspiring
March 3, 2023

This looks like an interesting solution, but if it doesn't update you're right, may not be something I can use.

 

Maybe an alternate approach would be better then--how about this. If we can't get the actual system time, what about if I specify a time with a slider (maybe 18.5 to represent 6:30PM/1830EST), and then add the value of Time() to it, so it appears that the clock is actually changing as time passes? Only wrinkle is I don't know how to format the output in an HH:MM format.

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
March 3, 2023

Maybe something like this:

s = effect("Slider Control")("Slider");

function padZero(n){ return (n < 10 ? "0" : "") + n }

baseSec = s*3600;
t = baseSec + time - inPoint;

hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
padZero(hr) + ":" + padZero(min) + ":" + padZero(sec)
Mylenium
Legend
March 2, 2023
brandonb96942845
Inspiring
March 2, 2023

You really don't understand the concept of "be helpful" do you? All this is Javascript, which might be helpful to a programmer, which I am not. So once again, this is an utterly worthless answer. I've asked a very simple question--so if the answer is as simple as you claim, is there a reason you can't provide a simple answer?

I've been banging my head on this the entire day and all you're doing is making it worse. If you can't actually provide a straightforward and concrete answer to my question, in the form of an expression or formula I can use in AfterEffects, don't bother responding to this or any future questions of mine.

Mylenium
Legend
March 2, 2023

AE fully supports the date() function and it's flavors, including time conversion or even different time zones. You can easily look this stuff up on the web.

 

Mylenium 

brandonb96942845
Inspiring
March 2, 2023

Sometimes I wonder if you read my entire posts or just look at the title and start typing. This reply, like so many I've seen from you, is utterly worthless. If you'd read my post, you'd know the second and third paragraphs state:

 


@brandonb96942845 wrote:

All the search results I can find talk about the Time() expression as it relates to the current time in the composition; I know there's a way do to this through an effect but I'd really just like to add it to the SourceText of a layer if at all possible. (And for bonus points would be helpful to be able to format it as 24-hour time, with zeroes padding on the hours.)

 

I'm sure there's a way to do it but after several hours of searching I'm coming up emptyhanded. Would be very grateful for anyone's help on this!


 

Thus, if you'd read me post in its entirety, you'd have realized that I've already tried searching the web, without success. I came here because I thought surely I could get help here that was more intelligent than "look it up on the web." Now, would you care to try again and actually try to be helpful this time?