Copy link to clipboard
Copied
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)
1 Correct answer
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
Copy link to clipboard
Copied
If you have iExpressions, you can use this one:
Counter Time Expression | mamoworld
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Amazing!
Copy link to clipboard
Copied
Do you can add the frames too in this expression for me, please?
Beyond minutes and secs...
I try this, is right?:
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;
ff = Math.floor(t/29.97).toString();
if (ff.length < 2) ff = "0" + ff;
mm + ":" + ss + ":" + ff
Copy link to clipboard
Copied
I guess I'd do it like this:
slider = comp("Comp 1").layer("Null 1").effect("Slider Control")("Slider");
t = parseInt(slider,10);
ff = timeToFrames(slider%1).toString();
if (ff.length < 2) ff = "0" + ff;
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 + ":" + ff
Dan
Copy link to clipboard
Copied
Thank you a lot!!!
Copy link to clipboard
Copied
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.

