Matthew Woodard
Matthew Woodard

Reputation: 754

jQuery FullCalendar is returning the year 1970

I have the calendar initiated and and its renders properly.

I am using a select dropdown to jump to a month. Here is my code.

HTML:

<select name="months">
    <option value="">Select a month ...</option>
    <option value="0">January</option>
    <option value="1">February</option>
    <option value="2">March</option>
    <option value="3">April</option>
    <option value="4">May</option>
    <option value="5">June</option>
    <option value="6">July</option>
    <option value="7">August</option>
    <option value="8">September</option>
    <option value="9">October</option>
    <option value="10">November</option>
    <option value="11">December</option>
</select>

JS:

jQuery('select[name="months"]').change(function() {
    var month = jQuery(this).val();

    // console.log(month);

    jQuery('#calendar').fullCalendar('gotoDate', 2016, month);

});

For some reason when I change the month the Calendar is jumping to January 1970.

Any ideas?

Upvotes: 0

Views: 612

Answers (1)

Alex Johnson
Alex Johnson

Reputation: 1574

Take a look at the fullCalendar docs for goToDate:

gotoDate

Moves the calendar to an arbitrary date.

.fullCalendar( 'gotoDate', date ), where date can be a Moment object, or anything the Moment constructor accepts.

When you change the date, you need to pass in a moment.js date, or something that moment can convert to a moment date. Because your date isn't a valid 'moment' date, it's defaulting your selected date to '0' epoch time.

The code you'll need is as follows:

jQuery('#calendar').fullCalendar('gotoDate', [momentObjectHere]);

Fun fact: The reasons you see the year 1970 in the result, is that 1970 is '0' in epoch time. It's a way of representing time as a number. You can read more about epoch time here if you're interested.

http://fullcalendar.io/docs/current_date/gotoDate/

Upvotes: 3

Related Questions