-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
2
  • see var d = new Date(); var n = d.getMonth(); Commented Dec 4, 2019 at 9:36
  • 1
    Date.now() returns a number, I'm surprised you're getting a string result in your first code block Commented Dec 4, 2019 at 9:41

3 Answers 3

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); 
Sign up to request clarification or add additional context in comments.

Comments

1

You need date object for this.

Try this:

let date = new Date();

console.log(date.getMonth()+1)

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.