Jquery FullCalendar.formatdate不工作

Jquery FullCalendar.formatdate不工作,jquery,fullcalendar,Jquery,Fullcalendar,我正在尝试将FullCalendar集成到php mysql。我使用了以下代码。我希望格式化日期,使其以yyyy/mm/dd格式出现,但当我使用format语句时,代码无法正常工作。如果我删除format date,它似乎可以工作,但会在数据库中插入0000/0000/000 00:00 我的代码: // Convert the allDay from string to boolean eventRender: function(event, element, view) { if

我正在尝试将FullCalendar集成到php mysql。我使用了以下代码。我希望格式化日期,使其以yyyy/mm/dd格式出现,但当我使用format语句时,代码无法正常工作。如果我删除format date,它似乎可以工作,但会在数据库中插入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');
},
谁能告诉我是什么问题吗?
如果我删除了格式日期,它就工作了,否则它就不工作了。但我必须格式化数据,以便将其正确插入数据库。我只想要date only,不需要小时。

首先,如果您要查找的是date only而不是小时,您可能应该使用:

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 V2()上不再存在
$.fullCalendar.formatDate
方法。 您可以将
矩.js
格式()
方法()一起使用

不要忘记导入
moment.js
并编辑
start
end
变量以:

start=moment(start).format('YYYY/MM/DD');
end=moment(end).format('YYYY/MM/DD');
它应该可以解决您的问题。

正如建议的那样:如果您不需要时间部分,请不要对其进行编码:

start = $.fullCalendar.formatDate(start, "yyyy-MM-dd");

另一个问题在于传递给ajax请求的参数字符串:

data: 'title='+ title+'&start='+ start +'&end='+ end  ,
此字符串不是url编码的

最简单的纠正方法是传递一个对象,并让jQuery处理编码:

data: {'title': title, 'start': start, 'end': end } ,

下面的代码应该可以做到这一点。(假设您有moment.min.js lib)

在某些版本中,“DDTHH:mm”添加将失败-打赌将其删除并使用纯日期格式。如果愿意,添加“Z”以补偿时区

select: function(start, end){

           var converted_start = moment(start).format('YYYY-MM-DD:HH:mm:ssZ');// the "Z" will adjust for time zone
           var converted_end = moment(end).format('YYYY-MM-DD:HH:mm:ssZ');

        },

这是mysql的问题吗?不,我需要日期格式应该在mysql的datetime格式字段中。只有代码的答案会被分解,特别是因为有现有的答案;对代码、关键功能或其不同之处进行解释;以和为例,查看现有的解决方案
select: function(start, end){

           var converted_start = moment(start).format('YYYY-MM-DD:HH:mm:ssZ');// the "Z" will adjust for time zone
           var converted_end = moment(end).format('YYYY-MM-DD:HH:mm:ssZ');

        },