aarontemp
aarontemp

Reputation: 171

How do I get fullcalendar to read date/time?

I am using fullcalendar on my project. My user will enter event information such as event name, date, and location. everything works but the date/time. when the user enters date and time it appears like this: 06/28/2016 10:00 AM

FullCalendar reads the date but doesn't read the time. What do i need to do so that it can read the time?

Here is my js for fullcalendar:

$(document).ready(function() {

  // page is now ready, initialize the calendar...

  $('#calendar').fullCalendar({
    // put your options and callbacks here

    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay'
    },
    weekends: true,

    events: 'http://www.familyevent.comli.com/events.php',

    eventRender: function(event) {
      if (event.allDay === 'true') {
        event.allDay = true;
      } else {
        event.allDay = false;
      }

    },
    eventClick: function(event) {
      alert("event start " + moment(event.start).format('MM/DD/YYYY hh:mm a') + " event end " +
        moment(event.end).format('MM/DD/YYYY hh:mm:ss'));
    }

  });

});

I put in eventClick to see what fullCalendar was reading. it gets the date but the time is always 12:00 AM

Upvotes: 1

Views: 1127

Answers (1)

user6269864
user6269864

Reputation:

Use moment.js that is already bundled with fullCalendar to convert the date to a format that fullcalendar will understand.

event.start = moment("06/28/2016 10:00 AM");

If it still doesn't work even after removing space before AM, and if your date format is well-defined, you can create the moment object step-by step, by adding the hours and minutes manually:

var time = ("06/28/2016 10:00 AM").split(" ")[1].split[":"];
event.start = moment("06/28/2016 10:00 AM").hours(time[0]).minutes(time[1]); //also add AM/PM handling

Upvotes: 1

Related Questions