使用 javascript 将 HH:MM:SS 转换为分钟
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32885682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:52:00 来源:igfitidea点击:
Convert HH:MM:SS into minute using javascript
提问by Anand
How can I Convert HH:MM:SS into minute using javascript ?
如何使用 javascript 将 HH:MM:SS 转换为分钟?
回答by Jordi Castilla
Use split and multiply per 60 ignoring seconds.
每 60 忽略秒使用拆分和乘法。
Taking this answeras base:
以这个答案为基础:
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);
Use split and multiply per 60 using seconds as decimal (thus is not full exact)
使用以秒为十进制的每 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));