Tekken
Tekken

Reputation: 63

Fullcalendar dayClick return wrong date

I'm trying to get the date of the clicked day on the calendar by using the function dayClick, I've used this for get the the date as object:

console.log(date.year());
console.log(date.month());
console.log(date.day());
var startDate = new Date(date.year(), date.month(), date.day(), 0, 0, 0);

so in this example I've clicked on August 6 2016 but in the output I get:

2016 - 7 - 6

but should be:

2016 - 8 - 6

what is wrong?

Upvotes: 1

Views: 586

Answers (1)

user6269864
user6269864

Reputation:

Both the JS Date object and moment.js objects return the month number starting from zero, not one.

So January is 0 and December is 11.

In any case you should not work with the date this way, use moment.js bundled with fullCalendar.

If it doesn't suit you, just use this to convert to JS Date object:

date.toDate();

This works because date is a moment.js object.

Upvotes: 1

Related Questions