Skip to main content
ti.s.cavalcanti
Inspiring
November 7, 2017
Answered

Expression to create a static Timecode

  • November 7, 2017
  • 2 replies
  • 3809 views

I need to create a "Timecode" so: 00:00, and this will show the value of a propertie, example: when the value 145 (corresponds to me like 145 seconds). So the Timecode get 2:24

Basically I want to convert a value (which I have as seconds) to minutes and seconds (00:00)

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

Something like this maybe:

t = parseInt(comp("Comp 1").layer("Null 1").effect("Slider Control")("Slider"),10);

mm = Math.floor(t/60).toString();

if (mm.length < 2) mm = "0" + mm;

ss = (t%60).toString();

if (ss.length < 2) ss = "0" + ss;

mm + ":" + ss

Dan

2 replies

Participant
February 17, 2022

Here is a super simple expression that will do this.

countTime = timeToCurrentFormat(time);
countTime.substr(3, 5);

 You can also just add how many frames you want to the (time) with something like (time+30) to start at 1 second if you're frames per second is 30. The .substr just trims the string generated by the timeToCurrentFormat so right now it is trimming from the 3rd character to the 5th. If you shift those numbers to something like (6,7) you can show seconds/frames  or (0, 5) for hours minutes or whatever you want.

Mathias Moehl
Community Expert
Community Expert
November 7, 2017

If you have iExpressions, you can use this one:

Counter Time Expression | mamoworld

counter_time_0.png

if you want to write your own expression, you need to convert the time to minutes and seconds as described here

Javascript seconds to minutes and seconds - Stack Overflow

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
ti.s.cavalcanti
Inspiring
November 7, 2017

How to aply this function in my expression?:

function fancyTimeFormat(time)
{ 
 
// Hours, minutes and seconds
 
var hrs = ~~(time / 3600);
 
var mins = ~~((time % 3600) / 60);
 
var secs = time % 60;

 
// Output like "1:01" or "4:03:59" or "123:03:59"
 
var ret = "";

 
if (hrs > 0) {
  ret
+= "" + hrs + ":" + (mins < 10 ? "0" : "");
 
}

  ret
+= "" + mins + ":" + (secs < 10 ? "0" : "");
  ret
+= "" + secs;
 
return ret;
}

I need the value of the property, or in this case, the effect value:

comp ("Comp 1"). layer ("Null 1"). effect ("Slider Control")

To be used as the base of seconds, and then get the result in minutes and seconds.

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
November 7, 2017

Something like this maybe:

t = parseInt(comp("Comp 1").layer("Null 1").effect("Slider Control")("Slider"),10);

mm = Math.floor(t/60).toString();

if (mm.length < 2) mm = "0" + mm;

ss = (t%60).toString();

if (ss.length < 2) ss = "0" + ss;

mm + ":" + ss

Dan