How to format date on FullCalendar on that way, wh

2019-08-03 01:40发布

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.

4条回答
贪生不怕死
2楼-- · 2019-08-03 02:41

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

查看更多
叛逆
3楼-- · 2019-08-03 02:42

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'));
查看更多
贼婆χ
4楼-- · 2019-08-03 02:44

My solution

var startFix= moment($.fullCalendar.formatDate(start, 'YYYY-MM-DD'));
查看更多
三岁会撩人
5楼-- · 2019-08-03 02:47

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/

查看更多
登录 后发表回答