Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting milliseconds to minutes to hours/minutes/seconds 1

Status
Not open for further replies.

knuckle05

Programmer
Dec 17, 2001
247
0
0
CA
Hi All,

I'm working on a time indicator to show where exactly I am in a movie clip.

In this format for ex:

HH:MM:SS.S / HH:MM:SS.S
00:00:02.0 / 00:10:00.0

This would indicate that 2 seconds have elapsed of the 10 minute video clip.

From my code I have call-back funtions which return me the elapsed time at every 100 milliseconds.

Anyhow, I receive my values back as milliseconds, for ex

something like

10000000000 / 9990000000000 (not actual numbers)

How could I convert thiese values into the desired format I indicated above? Any help would be appreciated as I'm not well-versed in js. Thanks
 
milliSecs = yourVariableHere

msSecs = (1000)
msMins = (msSecs * 60)
msHours = (msMins * 60)
numHours = Math.floor(milliSecs/msHours)
numMins = Math.floor((milliSecs - (numHours * msHours)) / msMins)
numSecs = Math.floor((milliSecs - (numHours * msHours) - (numMins * msMins))/ msSecs)


if (numSecs < 10){
numSecs = &quot;0&quot; + numSecs.toString
}
if (numMins < 10){
numMins = &quot;0&quot; + numMins.toString
}

resultString = numHours + &quot;:&quot; + numMins + &quot;:&quot; + numSecs Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
In the above code,

10 seconds returns
0:0 function toString() { [native code] } :10

60 seconds returns
0:0 function toString() { [native code] } :0 function toString() { [native code] }

and 60 minutes returns
1:0 function toString() { [native code] } :0 function toString() { [native code] }
 
Just remove the &quot;toString&quot;


milliSecs = 10000

msSecs = (1000)
msMins = (msSecs * 60)
msHours = (msMins * 60)
numHours = Math.floor(milliSecs/msHours)
numMins = Math.floor((milliSecs - (numHours * msHours)) / msMins)
numSecs = Math.floor((milliSecs - (numHours * msHours) - (numMins * msMins))/ msSecs)


if (numSecs < 10){
numSecs = &quot;0&quot; + numSecs
}
if (numMins < 10){
numMins = &quot;0&quot; + numMins
}

resultString = numHours + &quot;:&quot; + numMins + &quot;:&quot; + numSecs

alert (resultString) Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Hi Guys,

I've been trying to alter the code to incorporate the milliseconds as well, however, I'm not quite getting it. Any ideas?
 
numMillisecs = milliSecs - (numHours * msHours) - (numMins * msMins) - (numSecs * msSecs)


resultString = numHours + &quot;:&quot; + numMins + &quot;:&quot; + numSecs + &quot;.&quot; + numMillisecs Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top