Convert HH:MM:SS into minute using javascript

17,778

Use split and multiply per 60 ignoring seconds.

Taking this answer as 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)

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));
Share:
17,778
Anand
Author by

Anand

Updated on June 07, 2022

Comments

  • Anand
    Anand about 2 years

    How can I Convert HH:MM:SS into minute using javascript ?

  • adrichman
    adrichman almost 8 years
    this does not create a valid date object
  • jas-
    jas- almost 8 years
    Correct. Thanks for the heads up.