大家好我有一个代码片段,我想添加到我的Flash游戏中。它工作正常我只是难以让它显示milisecounds。任何帮助都会很棒!
function formatTime( time:Number ):String {
var remainder:Number;
var hours:Number = time / ( 60 * 60 );
remainder = hours - (Math.floor ( hours ));
hours = Math.floor(hours);
var minutes = remainder * 60;
remainder = minutes - (Math.floor ( minutes ));
minutes = Math.floor(minutes);
var seconds = remainder * 60;
remainder = seconds - (Math.floor ( seconds ));
seconds = Math.floor(seconds);
var hString:String = hours < 10 ? "0" + hours:"" + hours;
var mString:String = minutes < 10 ? "0" + minutes:"" + minutes;
var sString:String = seconds < 10 ? "0" + seconds:"" + seconds;
if (time < 0 || isNaN(time)){
return "00:00";
}
if (hours > 0) {
return hString + ":" + mString + ":" + sString;
}
else{
return mString + ":" + sString;
}
}
答案 0 :(得分:0)
要获得毫秒,你想要取time
的小数部分,就像那样:
var mseconds:Number=Math.floor((time-Math.floor(time))*1000);
var msString:String=(mseconds<10) ? "00"+mseconds :
(mseconds<100) ? "0"+mseconds : ""+mseconds;
然后将其添加到您形成的字符串中。