我试图使用此函数以毫秒为单位格式化持续时间,但它对我不起作用:
var msec_num = parseInt(duration, 10) / 100;
var hours = Math.floor(msec_num / 3600 );
var minutes = Math.floor((msec_num - (hours * 3600)) / 60);
var seconds = Math.floor((msec_num - (hours * 3600) - (minutes * 60)) / 60 / 1000 );
var milliseconds = ( msec_num - ((hours * 3600) - (minutes * 60) - (seconds)) / 1000 ) * 100;
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
if (milliseconds < 10) {milliseconds = "0"+milliseconds;}
var time = hours + ":" + minutes + ":" + seconds + ":" + milliseconds;
如果我使用该值(持续时间 = 1091ms)进行测试,它会给我这个:00:00:00:1091 ???
我怎么能弄清楚所有的价值都完美地工作?