PDA

View Full Version : Decimal to time



phaedo5
March 18th, 2009, 05:02 PM
I'm having trouble finding out how this would work in AS3.

I have a decimal number (4.14). That's a TotalTime variable of an flv. I want to convert that to something like 4:20.

What would i need to utilize in order to make this happen?

mpelland
March 18th, 2009, 05:15 PM
for that you could do something simple like
var minutes = totalTime.split(".")[0]
var seconds = Number(totalTime.split(".")[1]) * 60

that would give you minutes and seconds

rondog
March 18th, 2009, 05:16 PM
Here is a function to convert FLV total time into time format. You take the duration of the FLV in seconds and call returnTotalTime();



var videoDuration:Number = 4.14;
trace(returnTotalTime(videoDuration));
//traces "00:00:04" in string format

function returnTotalTime(seconds:Number):String
{
var minutes = Math.floor(seconds/60);
var remainingSec = seconds % 60;
var remainingMinutes = minutes % 60;
var hours = Math.floor(minutes/60);
var floatSeconds:Number = Math.floor((remainingSec - Math.floor(remainingSec))*100);
remainingSec = Math.floor(remainingSec);
return getTwoDigits(hours) + ":" + getTwoDigits(remainingMinutes) + ":" + getTwoDigits(remainingSec);
}

function getTwoDigits(number:Number):String
{
if (number < 10)
{
return "0" + number;
}
else
{
return number + "";
}
}

phaedo5
March 18th, 2009, 05:19 PM
Hmm so your flv is 4.14 seconds long?
Ha. Sorry. Left out the part where I mentioned that it was a rounded number.

phaedo5
March 18th, 2009, 05:22 PM
Here is a function to convert FLV total time into time format. You take the duration of the FLV in seconds and call returnTotalTime();


Awesome. Thank you!