使用javascript将HH:MM:SS转换为分钟

Ana*_*and 2 javascript string time

如何使用javascript将HH:MM:SS转换为分钟?

Jor*_*lla 11

使用split和multiply每60忽略秒.

这个答案为基础:

var hms = '02:04:33';   // your input string
var a = hms.split(':'); // split it at the colons

// Hours are worth 60 minutes.
var minutes = (+a[0]) * 60 + (+a[1]);

console.log(minutes);
Run Code Online (Sandbox Code Playgroud)

使用分数和乘法每60使用秒作为十进制(因此不完全准确)

var hms = '02:04:33';   // your input string
var a = hms.split(':'); // split it at the colons

// Hours are worth 60 minutes.
var minutes = (+a[0]) * 60 + (+a[1]);

console.log(minutes + "," + ((+a[2]) / 60));
Run Code Online (Sandbox Code Playgroud)