我正在尝试将 fullcalender 集成到 php mysql。我使用了以下代码。我想格式化日期,使其采用 yyyy/mm/dd 格式,但是当我使用格式语句时,代码无法正常工作。如果我删除格式日期,它似乎可以工作,但在数据库中插入 0000/0000/000 00:00 。
我的代码:
// Convert the allDay from string to boolean
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
}
else {
event.allDay = false;
}
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Sample Textbox:');
if (title) {
start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost/fullcalendar/demos/add_events.php',
data: 'title='+ title+'&start='+ start +'&end='+ end ,
type: "POST",
success: function(json) {
alert('Added Successfully');
alert(json);
}
});
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
谁能告诉我这是什么问题? 如果我删除格式日期,它就可以工作,否则它就不起作用。但我必须格式化数据才能将其正确插入数据库中。我只想约会,不需要时间。
最佳答案
首先,如果您只查找日期而不是时间,您可能应该使用:
start = $.fullCalendar.formatDate(start, "yyyy/MM/dd");
end = $.fullCalendar.formatDate(end, "yyyy/MM/dd");
而不是这个:
start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
如果您删除日期格式,它似乎可以工作,因为它像时间戳一样插入日期(它看起来像时间戳)。 尝试将数据库结构类型更改为 VARCHAR,您将看到如下内容:
1405468800000
<小时/>
当您使用 dateFormat 函数时,您应该查看网络浏览器控制台日志。您可能会看到:
Uncaught TypeError: undefined is not a function
这是因为 fullCalendar V2 ( changeLog ) 上不再存在 $.fullCalendar.formatDate
方法。
您可以将 Moment.js
与 .format()
方法 ( doc ) 结合使用。
不要忘记导入 moment.js
并将 start
和 end
变量编辑为:
start=moment(start).format('YYYY/MM/DD');
end=moment(end).format('YYYY/MM/DD');
它应该可以解决您的问题。
关于jquery - fullcalendar.formatdate 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24729721/