Javascript Date getMinutes()

Introduction

Javascript Date getMinutes() returns the date's minutes as a number between 0 and 59.

var d = new Date('December 25, 2020 23:15:30');
var minutes = d.getMinutes();

console.log(minutes); // 15

Using getHours(), getMinutes(), and getSeconds() to display the time:

function addZero(i) {
  if (i < 10) {
    i = "0" + i;/*from   ww w .ja v a2s  . c om*/
  }
  return i;
}

var d = new Date();
var h = addZero(d.getHours());
var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds());
console.log(h + ":" + m + ":" + s);



PreviousNext

Related