如何用前导零显示时间? [英] How can I display time with leading zeros?
本文介绍了如何用前导零显示时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个时间函数来计算媒体播放的时间。它不显示任何前导零。如何让它显示任何前导零?
I have created a time function to calculate time as media is playing. It does not display any leading zeros. How can I make it display any leading zeros?
function converttoTime(timeInSeconds)
{
var minutes = Math.round(Math.floor(timeInSeconds / 60));
var seconds = Math.round(timeInSeconds - minutes * 60);
//var hours = Math.round(Math.floor(timeInSeconds / 3600));
//time = time - hours * 3600;
var time=minutes+':'+seconds;
return time;
}
推荐答案
这应该有效:
var time=('0' + minutes).slice(-2)+':'+('0' + seconds).slice(-2);
这篇关于如何用前导零显示时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文