http://arshaw.com/fullcalendar/我想在调用select函数时在我的服务器上创建一个事件。
这是我的代码:
select: function(start, end, allDay) {
$.ajax({
type: "POST",
url: "/account/availability",
data: {action: "create", start: start, end: start},
success: function(id) {
calendar.fullCalendar('renderEvent',{
title: "My Event",
start: start,
end: end,
allDay: true,
id: id
});
}
});
}
问题是,开始和结束的日期都是一种可靠的格式,例如“Thu Jan 09 2014 00:00:00 GMT + 0100(MitteleuropäischeZeit)”。如何将该格式转换为php,以便我可以将这些事件轻松保存到我的数据库中?
答案 0 :(得分:1)
只需使用strtotime,有时strtotime将无法在包含此类位置的字符串中使用,因此请确保清理您的值,在此示例中我使用了explode。
$date = 'Thu Jan 09 2014 00:00:00 GMT+0100 (Mitteleuropäische Zeit)';
$time = strtotime(current(explode("(",$date)));
echo Date('Y / M / d', $time);
$date = 'Thu Jan 09 2014 00:00:00 GMT+0100 (Mitteleuropäische Zeit)';
$time = strtotime(current(explode("(",$date)));
echo Date('Y / M / d', $time);
这里的工作示例:example
答案 1 :(得分:1)
嗨我遇到了同样的问题,但在javaScript
。但我使用了fullCalander内置函数。
var dd = $.fullCalendar.formatDate(date,"yyyy-MM-dd");
检查我的问题here。
答案 2 :(得分:0)
你可以使用fullcalendar convert date function
这样做select: function(start, end, allDay) {
//$.fullCalendar.formatDate( date, formatString [, options ] ) -> String
// Notice that i used the variable assign to calendar var
// var calendar = $('#calendar').fullCalendar({ .....
var startDate = calendar.formatDate( start, "yyyy-MM-dd");
var endDate = calendar.formatDate( end, "yyyy-MM-dd");
$.ajax({
type: "POST",
url: "/account/availability",
data: {action: "create", start: start, end: start},
success: function(id) {
calendar.fullCalendar('renderEvent',{
title: "My Event",
start: start,
end: end,
allDay: true,
id: id
});
}
});
}