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 user2666909user26669094 Answers
Reset to default 4Since 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
版权声明:本文标题:javascript - How to format date on FullCalendar on that way, when I click on event? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741464115a2380208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论