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.
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'));