我正在尝试将fullcalender集成到php mysql中。我使用了以下代码。我想格式化日期,使其以yyyy / mm / dd格式出现,但是当我使用format语句时,代码无法正常工作。删除格式日期似乎有效,但在数据库中插入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函数时,应在Web浏览器控制台日志中查找。您可能会看到:
Uncaught TypeError: undefined is not a function
这是因为
$.fullCalendar.formatDate
方法在fullCalendar V2(changeLog)上不再存在。您可以将
Moment.js
与.format()
方法(doc)一起使用。不要忘记导入
moment.js
并将start
和end
变量编辑为:start=moment(start).format('YYYY/MM/DD');
end=moment(end).format('YYYY/MM/DD');
它应该解决您的问题。