-4

I'm trying to get month from my date variable.

date=Date.now();

console.log(date); 
>>2019-12-04T08:55:48.972Z

I want to get the month from this date but when I'm using getMonth(), I'm getting error.

console.log(date.getMonth());
error:- getMonth is not a function

3 Answers3

2

You can try this

let date= new Date();

console.log(date.getMonth()); 
let date= new Date('2019-10-04T08:55:48.972Z');

console.log(date.getMonth()+1); 
Akshay Sharma
  • 1,042
  • 1
  • 8
  • 21
1

You need date object for this.

Try this:

let date = new Date();

console.log(date.getMonth()+1)
Saurabh Agrawal
  • 7,581
  • 2
  • 27
  • 51
1

Try to remove the .now. It should be date = new Date();

Lavi Arzi
  • 99
  • 2
  • 10