仅在javascript中将HH:MM:SS字符串转换为秒 [英] Convert HH:MM:SS string to seconds only in javascript
本文介绍了仅在javascript中将HH:MM:SS字符串转换为秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类似的要求:将HH:MM:SS格式的时间转换为秒只有?
但是在javascript中。我已经看到很多将秒转换成不同格式的例子,但不是HH:MM:SS转换为秒。任何帮助,将不胜感激。
but in javascript. I have seen many examples of converting seconds into different formats but not HH:MM:SS into seconds. Any help would be appreciated.
推荐答案
试试这个:
var hms = '02:04:33'; // your input string
var a = hms.split(':'); // split it at the colons
// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
console.log(seconds);
这篇关于仅在javascript中将HH:MM:SS字符串转换为秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文