[ActionScript 3.0] AS3 时间格式化方法

 1 /**
 2  * 格式化时间,格式 00:00:00
 3  * @param   total 总时间(毫秒)
 4  */
 5 function getFormatTime(total:uint):String
 6 {
 7     if (total/1000 < 60 && total/1000 >0) {
 8         var s0:uint = total / 1000 >> 0;
 9         return s0 < 10 ? "00:0" + s0.toString() : "00:" + s0.toString();
10     } else {
11         var h:uint = (total / 3600000) >> 0;
12         var m:uint = ((total -h*3600000)/60000)>>0;
13         var s:uint = ((total -h*3600000 - m*60000)/1000)>>0;
14         var hh:String = h < 10 ? "0" + h:h.toString();
15         var mm:String = m < 10 ? "0" + m:m.toString();
16         var ss:String = s < 10 ? "0" + s:s.toString();
17         var arr:Vector.<String> = new Vector.<String>();
18         (h > 0) ? arr.push(hh):null;
19         (h > 0|| m > 0 ) ? arr.push(mm) : null;
20         (h > 0|| m > 0 || s > 0 )  ? arr.push(ss) : null;
21         return arr.join(":");
22     }
23 }

 

------------------------------------------------------------------ Always put yourself in the other's shoes.If you feel that it hurts you,it probably hurts others,too.------------------------------------------------------------------
posted on 2015-12-11 15:00  晏过留痕  阅读(224)  评论(0编辑  收藏  举报