Actionscript 3 as3获取;“小时”;以毫秒为单位的mp3

Actionscript 3 as3获取;“小时”;以毫秒为单位的mp3,actionscript-3,flash,date,datetime,time,Actionscript 3,Flash,Date,Datetime,Time,在As3中,以下代码获取分钟和秒数: var minutes:uint = Math.floor(PrayPrayer.position / 1000 / 60); var seconds:uint = Math.floor(PrayPrayer.position / 1000) % 60; 但是如果你在听一个超过小时的音频讲话呢 从mp3谈话中获得小时数所需的数学是什么? var hours:uint = Math.floor(PrayPrayer.position / 1000) % 6

在As3中,以下代码获取分钟和秒数:

var minutes:uint = Math.floor(PrayPrayer.position / 1000 / 60);
var seconds:uint = Math.floor(PrayPrayer.position / 1000) % 60;
但是如果你在听一个超过小时的音频讲话呢

从mp3谈话中获得小时数所需的数学是什么?

 var hours:uint = Math.floor(PrayPrayer.position / 1000) % 60    & (((???????)));

这是我的转换方法:

    public static var MINUTE:Number = 60;
    public static var HOUR:Number = 60 * MINUTE;
    public static var DAY:Number = 24 * HOUR;

        /**
     * returns string created from seconds value in following format hours:minutes:seconds, i.e. 121 seconds will be displayed as 00:02:01
     * @param   seconds <i>Number</i>
     * @return <i>String</i>
     */
    public static function secondsToHMS(seconds:Number, doNotRound:Boolean = false):String
    {
        var _bNegative:Boolean = seconds < 0;

        seconds = Math.abs(seconds);

        var time:Number = (doNotRound) ? seconds:Math.round(seconds);

        var ms:Number;
        var msec:String;

        if (doNotRound)
        {
            ms = seconds - (seconds | 0);
            msec = prependZeros((ms * 1000) | 0, 3);
        }


        var sec:Number = (time | 0) % MINUTE;

        var min:Number = Math.floor((time / MINUTE) % MINUTE);

        var hrs:Number = Math.floor(time / HOUR);
        //
        return (_bNegative ? "-":"") +
               ((hrs > 9) ? "":"0") + hrs + ":" +
               ((min > 9) ? "":"0") + min + ":" +
               ((sec > 9) ? "":"0") + sec +
               (doNotRound ? "." + msec:"");
    }
公共静态变量分钟数:数字=60;
公共静态变量小时:数字=60*分钟;
公共静态var日:数字=24*小时;
/**
*返回从秒值创建的字符串,格式为小时:分钟:秒,即121秒将显示为00:02:01
*@param秒数
*@返回字符串
*/
公共静态函数secondsToHMS(秒数:Number,doNotRound:Boolean=false):字符串
{
var _b负:布尔值=秒<0;
秒=Math.abs(秒);
变量时间:Number=(doNotRound)?秒:数学四舍五入(秒);
var-ms:数量;
var-msec:字符串;
如果(doNotRound)
{
ms=秒-(秒| 0);
msec=prependZeros((ms*1000)| 0,3);
}
变量秒:数字=(时间| 0)%min;
变量最小值:数字=数学楼层((时间/分钟)%分钟);
变量小时数:数字=数学楼层(时间/小时);
//
返回(_b负?”-“:”)+
((小时数>9)?“”:“0”)+小时数+”:“+
((最小值>9)?“”:“0”)+最小值+”:“+
((秒>9)?“”:“0”)+秒+
(doNotRound?“+msec:”);
}

prependZeros是在给定字符串前面添加“0”的另一个实用程序。

因此
PrayParyer.position
以毫秒为单位。您的
minutes
行除以1000得到秒,然后除以60从秒到分钟。您的
seconds
行正在查看剩余部分

您在
hours
行中开始的内容使用的是
%
,因此将查看其余部分-您在那里使用的是秒
%
是模运算符。它给出整数除法的余数。那你的台词呢

var seconds:uint = Math.floor(PrayPrayer.position / 1000) % 60;
正在查找秒数(PrayPrayer.position/1000),它可能是2337,除以60,只保留余数。2337/60=38剩余57,因此2337%60将为57

找到时间的一个简单方法是对你的分钟使用同样的技巧

var minutes:uint = Math.floor(PrayPrayer.position / 1000 / 60);
var seconds:uint = Math.floor(PrayPrayer.position / 1000) % 60;
var hours:uint = Math.floor(minutes / 60);
minutes %= 60;  // same as minutes = minutes % 60.  Forces minutes to be between 0 and 59.