14

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

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
Anand Rajagopal
  • 1,593
  • 6
  • 24
  • 40

2 Answers2

34

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));
Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
-8

To know time functions & formats in JS you must read the manual.

var date = new Date();
console.log(date.getMinutes());
jas-
  • 1,801
  • 1
  • 18
  • 30