• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

I have a variable that is in decimal seconds.

Example: 92.5

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

TOPICS
Acrobat SDK and JavaScript

Views

692

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 16, 2018 Aug 16, 2018

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;

Votes

Translate

Translate
Community Expert ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

So 0.5 is 50 seconds? Not 30?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

Or is that in hundreds of a second?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

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

and the value will never exceed 1 hour.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

thank you so very much!!

One last question:

How do I limit milliseconds to just 2 digits?

Since my input is a variable, I, sometimes, get something like 1:32.50.00000000045

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

Change this:

var remainder = (v-seconds)*100;

To:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

THANKS!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 18, 2018 Aug 18, 2018

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 18, 2018 Aug 18, 2018

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 18, 2018 Aug 18, 2018

Copy link to clipboard

Copied

LATEST

UPDATE: SOLVED

Did this:

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

v-=(minutes*60);  

var seconds = Math.floor(v); 

var secondsStr = seconds;

if(seconds<10) {secondsStr="0"+seconds;}

else {secondsStr=""+seconds;}

 

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines