admin管理员组

文章数量:1289875

How to format date on FullCalendar on that way, when I click on event? (for example) and use this code:

  eventClick: function( calEvent, jsEvent, view ){
    alert('start: ' + calEvent.start);
    alert('end: ' + calEvent.end);
  },

that alert show something like

start: 12/28/2013 14:55   
end: 12/28/2013 18:55

instead of "Tue Dec 28 2013 ... "

Any suggestions will be appreciated.

How to format date on FullCalendar on that way, when I click on event? (for example) and use this code:

  eventClick: function( calEvent, jsEvent, view ){
    alert('start: ' + calEvent.start);
    alert('end: ' + calEvent.end);
  },

that alert show something like

start: 12/28/2013 14:55   
end: 12/28/2013 18:55

instead of "Tue Dec 28 2013 ... "

Any suggestions will be appreciated.

Share Improve this question edited Jul 3, 2014 at 8:54 Nazik 8,44427 gold badges79 silver badges126 bronze badges asked Aug 9, 2013 at 6:35 user2666909user2666909
Add a ment  | 

4 Answers 4

Reset to default 4

Since fullcalendars' event start and end properties are javascript Date objects, it is responsibility of the code that displays them to handle their formatting, they don't have a specific format by themselves.

The easiest way I found to handle dates in javascript is to use moment.js.

Formatting your date in your alert would then be something like

alert('start: ' + moment(calEvent.start).format('DD/MM/YYYYhh:mm'));

Update: This answer provides a solution for version 1 of FullCalendar. From version 2 Moment.js is used by FullCalendar, and this answer is not longer valid

Moment.js is a really great library, but you could also use the formatDate() function provided by FullCalendar if you don't want to add another dependency.

It works like this:

alert('start: ' + 
     $.fullCalendar.formatDate(calEvent.start, 'dd/MM/yyyy HH:mm'));

You can check out the documentation for formatDate() here: https://fullcalendar.io/docs1/utilities/formatDate/

This worked for me;
var startDate =$.fullCalendar.moment(event.start).format('YYYY/MM/DD');

My solution

var startFix= moment($.fullCalendar.formatDate(start, 'YYYY-MM-DD'));

本文标签: javascriptHow to format date on FullCalendar on that waywhen I click on eventStack Overflow