5

JavaScript では、ミリ秒単位の変数 Time があります。

この値を効率的にフォーマットに変換する組み込み関数があるかどうかを知りたいMinutes:Secondsです。

そうでない場合は、ユーティリティ関数を教えてください。

例:

から

462000 milliseconds

7:42
4

6 に答える 6

13

オブジェクトを作成しDate、ミリ秒をパラメーターとして渡すだけです。

var date = new Date(milliseconds);
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
alert(((h * 60) + m) + ":" + s);
于 2012-11-28T09:30:33.927 に答える
6

ご支援いただきありがとうございます。最後に、このソリューションを思いつきました。他の人に役立つことを願っています。

使用する:

var videoDuration = convertMillisecondsToDigitalClock(18050200).clock; // CONVERT DATE TO DIGITAL FORMAT

// CONVERT MILLISECONDS TO DIGITAL CLOCK FORMAT
function convertMillisecondsToDigitalClock(ms) {
    hours = Math.floor(ms / 3600000), // 1 Hour = 36000 Milliseconds
    minutes = Math.floor((ms % 3600000) / 60000), // 1 Minutes = 60000 Milliseconds
    seconds = Math.floor(((ms % 360000) % 60000) / 1000) // 1 Second = 1000 Milliseconds
        return {
        hours : hours,
        minutes : minutes,
        seconds : seconds,
        clock : hours + ":" + minutes + ":" + seconds
    };
}
于 2012-11-28T10:51:34.330 に答える
3

プロジェクトで既にMoment.jsを使用している場合は、 moment.duration関数を使用できます。

こんな感じで使えます

var mm = moment.duration(37250000);
console.log(mm.hours() + ':' + mm.minutes() + ':' + mm.seconds());

出力: 10:20:50

jsbinサンプルを参照

于 2015-08-11T06:53:34.577 に答える
2

自分で変換するのは簡単です:

var t = 462000
parseInt(t / 1000 / 60) + ":" + (t / 1000 % 60)
于 2012-11-28T09:43:31.037 に答える
0
function msToMS(ms) {
    var M = Math.floor(ms / 60000);
    ms -= M * 60000;
    var S = ms / 1000;
    return M + ":" + S;
}
于 2012-11-28T09:35:12.137 に答える