Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
115
rated 0 times [  119] [ 4]  / answers: 1 / hits: 193566  / 12 Years ago, fri, march 9, 2012, 12:00:00

I am having similar requirement as this: Convert time in HH:MM:SS format to seconds only?


but in javascript. I have seen many examples of converting seconds into different formats but not HH:MM:SS into seconds.


More From » time

 Answers
88

Try this:



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);

[#86944] Thursday, March 8, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jimmieo

Total Points: 515
Total Questions: 102
Total Answers: 110

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;