javascript 当我单击事件时,如何以这种方式在 FullCalendar 上格式化日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18141261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to format date on FullCalendar on that way, when I click on event?
提问by Regin Larsen
How to format date on FullCalendar on that way, when I click on event? (for example) and use this code:
当我单击事件时,如何以这种方式在 FullCalendar 上格式化日期?(例如)并使用此代码:
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 ... "
代替 "Tue Dec 28 2013 ... "
Any suggestions will be appreciated.
任何建议将不胜感激。
回答by Raibaz
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.
由于 fullcalendars 的事件开始和结束属性是 javascriptDate
对象,显示它们的代码负责处理它们的格式,它们本身没有特定的格式。
The easiest way I found to handle dates in javascript is to use moment.js.
我发现在 javascript 中处理日期的最简单方法是使用moment.js。
Formatting your date in your alert would then be something like
在您的警报中格式化您的日期将类似于
alert('start: ' + moment(calEvent.start).format('DD/MM/YYYYhh:mm'));
回答by Regin Larsen
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
更新:此答案为 FullCalendar 的第 1 版提供了解决方案。从版本 2 Moment.js 被 FullCalendar 使用,这个答案不再有效
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.
Moment.js 是一个非常棒的库,但formatDate()
如果您不想添加其他依赖项,也可以使用FullCalendar 提供的函数。
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/
您可以在formatDate()
此处查看文档:https: //fullcalendar.io/docs1/utilities/formatDate/
回答by Vané Zulu
This worked for me;
var startDate =$.fullCalendar.moment(event.start).format('YYYY/MM/DD');
这对我有用;
var startDate =$.fullCalendar.moment(event.start).format('YYYY/MM/DD');
回答by Alejandro Aranda
My solution
我的解决方案
var startFix= moment($.fullCalendar.formatDate(start, 'YYYY-MM-DD'));