Skip to main content
ak312
Participating Frequently
Aug 16, 2018 4:45 PM UTC
Answered

How to convert seconds (decimal value) into minutes:seconds:miliseconds (if seconds > 60)

I have a variable that is in decimal seconds.

Example: 92.5

How do I convert it to 1:32:50?

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Aug 16, 2018 7:53 PM UTC

Sorry, 92.5 is 1:32.50 (that is 1 minute 32 seconds and 50 milliseconds)

and the value will never exceed 1 hour.


Then you can use this code:

var v = 92.5;

var minutes = Math.floor(v/60);

v-=(minutes*60);

var seconds = Math.floor(v);

var remainder = (v-seconds)*100;

var result = minutes + ":" + seconds + ":" + remainder;

12 replies

ak312
ak312Author
Participating Frequently
Aug 18, 2018 12:17 AM UTC

Hi try67,

How difficult is it to find a solution to the next little bug:

if "seconds" end up being between 1 and 9, Adobe omitting the zero,

and the result looks like: 1:2.55 instead of 1:02.55

Did I say I really appreciate your help?

Translate
try67
Community Expert
Community Expert
Aug 18, 2018 8:25 AM UTC

Use this:

var v = 92.5;

var minutes = Math.floor(v/60);

v-=(minutes*60);

var seconds = Math.floor(v);

var secondsStr = (seconds<10) : "0"+seconds ? ""+seconds;

var remainder = Math.round((v-seconds)*100);

var result = minutes + ":" + secondsStr + ":" + remainder;

Translate
ak312
ak312Author
Participating Frequently
Aug 19, 2018 12:05 AM UTC

For some reason, it keeps giving me the syntax error.

I checked all of the punctuation and it doesn't make any sense.

Translate
try67
Community Expert
Community Expert
Aug 16, 2018 4:49 PM UTC

So 0.5 is 50 seconds? Not 30?

Translate
try67
Community Expert
Community Expert
Aug 16, 2018 4:50 PM UTC

Or is that in hundreds of a second?

Translate
try67
Community Expert
Community Expert
Aug 16, 2018 4:57 PM UTC

Also, can the value exceed one hour? If so, do you want to display that separately, or just as minutes?

Translate