<分区>
我正在创建一个基于 JavaScript 的日历,使用 full-calendar.js 作为主干。
因此,为了将新的 event
插入 MySQL 数据库,我有以下代码片段:
$.post("http://localhost/calendar/index.php/calendar/insert_event",
{
title : title,
start : start,
end : end,
allDay : allDay,
url : ''
},
function(answer) {
console.log(answer);
}
);
开始
和结束
日期只是Date()
对象:
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
在 calendar.php
Controller 中,我得到以下输出:
{"title":"lunch",
"start":"Tue Oct 08 2013 08:00:00 GMT-0700 (Pacific Standard Time)",
"end":"Tue Oct 08 2013 08:30:00 GMT-0700 (Pacific Standard Time)",
"allDay":"false",
"url":""}
start
和 end
是 MySQL 表中的 DATETIME
类型,其中的列具有与上面相同的类型。
当我使用 CodeIgniter 的
Active Record 函数执行 insert
时,它会插入到表中而不会出现其他问题。但是,当我查看 MySQL
数据库以查看输出时,我看到:
mysql> select * from calendar_utility;
+----+-----+-------+---------------------+---------------------+--------+
| id | url | title | start | end | allday |
+----+-----+-------+---------------------+---------------------+--------+
| 1 | | lunch | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 0 |
+----+-----+-------+---------------------+---------------------+--------+
1 row in set (0.00 sec)
如何更正 JavaScript
Date()
的格式以正确插入 MySQL 数据库?