gpt4 book ai didi

jquery - 我怎样才能像这样显示视频当前和持续时间 00 :25/00:30?

转载 作者:行者123 更新时间:2023-12-02 04:09:51 25 4
gpt4 key购买 nike

我想以不同的格式显示视频 currentTimeduration

现在显示的方式是:

0:9/0:33

我希望它像这样显示:

00:09/00:33

或者如果视频时长超过 1 分钟

03:10/12:27

我现在的代码

    video.on('timeupdate', function() {

// Set to minute and seconds
var time = video[0].currentTime;
var minutes = Math.floor(time / 60);
var seconds = Math.floor(time);

// Set the current play value
currentTimer.text(minutes + ':' + seconds);
});

video.on('loadedmetadata', function() {

// Set to minute and seconds
var time = video[0].duration;
var minutes = Math.floor(time / 60);
var seconds = Math.floor(time);

// Set the video duration
durationTimer.text(minutes + ':' + seconds);
});

最佳答案

这段代码应该做你想做的:

function format(s) {
var m = Math.floor(s / 60);
m = (m >= 10) ? m : "0" + m;
s = Math.floor(s % 60);
s = (s >= 10) ? s : "0" + s;
return m + ":" + s;
}

alert(format(120));
alert(format(250));
alert(format(31));

关于jquery - 我怎样才能像这样显示视频当前和持续时间 00 :25/00:30?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37322022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com