Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- Acrobat SDK
- How to convert seconds (decimal value) into minute...

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/td-p/10053209
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

Community Guidelines

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

Most Valuable Participant
,
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;

12
Replies
12

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053210#M19447
Aug 16, 2018
Aug 16, 2018

Copy link to clipboard

Copied

So 0.5 is 50 seconds? Not 30?

Community Guidelines

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

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053211#M19448
Aug 16, 2018
Aug 16, 2018

Copy link to clipboard

Copied

Or is that in hundreds of a second?

Community Guidelines

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

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053212#M19449
Aug 16, 2018
Aug 16, 2018

Copy link to clipboard

Copied

Community Guidelines

ak312
AUTHOR

Community Beginner
,

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053213#M19450
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.

Community Guidelines

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053214#M19451
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;

Community Guidelines

ak312
AUTHOR

Community Beginner
,

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053215#M19452
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

Community Guidelines

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053216#M19453
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);

Community Guidelines

ak312
AUTHOR

Community Beginner
,

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053217#M19454
Aug 16, 2018
Aug 16, 2018

Copy link to clipboard

Copied

THANKS!!!

Community Guidelines

ak312
AUTHOR

Community Beginner
,

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053218#M19455
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?

Community Guidelines

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053219#M19456
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;

Community Guidelines

ak312
AUTHOR

Community Beginner
,

/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053220#M19457
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.

Community Guidelines

ak312
AUTHOR

Community Beginner
,

LATEST
/t5/acrobat-sdk/how-to-convert-seconds-decimal-value-into-minutes-seconds-miliseconds-if-seconds-gt-60/m-p/10053221#M19458
Aug 18, 2018
Aug 18, 2018

Copy link to clipboard

Copied

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;

Community Guidelines

Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2021 Adobe. All rights reserved.