Skip to main content
ak312
Participating Frequently
August 16, 2018
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
August 16, 2018

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
August 18, 2018

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
August 18, 2018

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
August 19, 2018

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
August 16, 2018

So 0.5 is 50 seconds? Not 30?

Translate
try67
Community Expert
Community Expert
August 16, 2018

Or is that in hundreds of a second?

Translate
try67
Community Expert
Community Expert
August 16, 2018

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

Translate