Search code examples
fullcalendar

Add End Time for FullCalendar's Week and Daily View


I am using FullCalendar v2 now and I found it is quite useful. However, I have encountered a problem when I want to show the end time of an event.

I want to show both start time and end time within a day in week and daily view like "09:00-17:00". I have found a solution in Display ending time in fullcalendar week view only but it seems a v1 version. I use this in v2 and failed.

How can I show both start time and end time within a day?


Solution

  • The answer here: Fullcalendar event's end time is missing works for version 1.6.1. However, the formatDates function has been replaced by formatRange in v2. So, use

    eventAfterRender: function(event, $el, view) {
            var formattedTime = $.fullCalendar.formatRange(event.start, event.end, "HH:mm");
            // If FullCalendar has removed the title div, then add the title to the time div like FullCalendar would do
            if($el.find(".fc-event-title").length === 0) {
                $el.find(".fc-event-time").text(formattedTime + " - " + event.title);
            }
            else {
                $el.find(".fc-event-time").text(formattedTime);
            }
        }