-1

I have a time format which is for example 1:50:60 (Hours:Minutes:Seconds) or also could be 00:50:60 (Minutes:Seconds) - depends. Now i want to convert that value hours, minutes, seconds to Seconds. So 1:50:60 would be 6660 seconds.

amphetamachine
  • 27,620
  • 12
  • 60
  • 72

2 Answers2

1

Try the below code

var hms = '09:05:03';
var s = hms.split(':');

var seconds = (+s[0]) * 60 * 60 + (+s[1]) * 60 + (+s[2]); 
console.log(seconds);
var hm = '00:55:03';
var s = hm.split(':');

var seconds = (+s[0]) * 60 * 60 + (+s[1]) * 60 + (+s[2]); 

console.log(seconds);
Ibrahim Shaikh
  • 388
  • 2
  • 18
0

Try this:

var hms = '01:50:60';   // 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);
mohan rathour
  • 420
  • 2
  • 12