Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the month name instead of month number in javascript? [duplicate]

Tags:

javascript

Here is my Code:
var listDate = [];
var startDate ='2017-02-01';
var endDate = '2017-02-10';
var dateMove = new Date(startDate);
var strDate = startDate;

while (strDate < endDate){
  var strDate = dateMove.toISOString().slice(0,10);
  listDate.push(strDate);
  dateMove.setDate(dateMove.getDate()+1);
};
console.log(listDate);

//["2017-02-01", "2017-02-02", "2017-02-03", "2017-02-04", "2017-02-05", "2017-02-06", "2017-02-07", "2017-02-08", "2017-02-09", "2017-02-10"]

it gives me the output with the month number like 2017-02-01, but i need the month name instead of month number. Pleae Help.

like image 916
ABHISHEK S Avatar asked Jul 13 '17 07:07

ABHISHEK S


1 Answers

try this simple way : Create an array with all the month name's, and so use your index as key to find the good month.

var monthNames = ["January", "February", "March", "April", "May","June","July", "August", "September", "October", "November","December"];

var d = new Date();
console.log("The current month is " + monthNames[d.getMonth()]);
like image 158
kumbhani bhavesh Avatar answered Nov 15 '22 00:11

kumbhani bhavesh