Javascript Date getMonth()

Introduction

Javascript Date getMonth() returns the month of the date, where 0 represents January and 11 represents December.

Return value

An integer number, between 0 and 11, representing the month in the given date according to local time. 0 corresponds to January, 1 to February, and so on.

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

console.log(month); // 11

January is 0, February is 1, and so on.

var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";

let d = new Date();
let n = month[d.getMonth()];
console.log(n);/*from  www.j av  a 2  s  . c o m*/

To get the full name of a month, "January" for example, use Intl.DateTimeFormat():

var d = new Date('December 25, 2020 23:15:30');
var options = { month: 'long'};
console.log(new Intl.DateTimeFormat('en-US', options).format(d));
console.log(new Intl.DateTimeFormat('de-DE', options).format(d));



PreviousNext

Related