phunder
phunder

Reputation: 1703

Date object not returning the expected year

I am trying to get today's date using a JavaScript date object. When I do I run the following code:

var date = new Date();
date = new Date(date.getYear(), date.getMonth(), 1);

I get this result:

Mon Aug 01 112 00:00:00 GMT +0200

Instead of today's date. I have used this exact code before with no issues. Am I doing something wrong?

Upvotes: 0

Views: 86

Answers (1)

xdazz
xdazz

Reputation: 160833

Use date.getFullYear() instead of date.getYear().

getYear is no longer used and has been replaced by the getFullYear method.

The getYear method returns the year minus 1900.

Upvotes: 2

Related Questions