fullcalender.formatdate不工作

use*_*579 1 jquery fullcalendar

我正在尝试将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');
},
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这是什么问题?如果我删除格式日期它正在工作,否则它不起作用.但我必须格式化数据才能将其正确插入数据库中.我只想要约会,不需要几个小时.

Tif*_*ifa 11

首先,如果您只查找日期而不是小时,您应该使用:

start = $.fullCalendar.formatDate(start, "yyyy/MM/dd");
end = $.fullCalendar.formatDate(end, "yyyy/MM/dd");
Run Code Online (Sandbox Code Playgroud)

而不是这个:

start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)

如果你删除日期格式它似乎工作,因为它插入日期像时间戳(它看起来像时间戳).尝试将数据库结构类型更改为VARCHAR,您将看到如下内容:

1405468800000
Run Code Online (Sandbox Code Playgroud)

使用dateFormat函数时,应查看Web浏览器控制台日志.你可能会看到:

Uncaught TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)

这是因为$.fullCalendar.formatDatefullCalendar V2(changeLog)上不再存在方法.您可以使用Moment.js.format()方法(DOC).

不要忘记导入moment.js和编辑您的startend变量:

start=moment(start).format('YYYY/MM/DD');
end=moment(end).format('YYYY/MM/DD');
Run Code Online (Sandbox Code Playgroud)

它应该解决你的问题.


小智 5

下面的代码应该可以解决问题.(假设你有moment.min.js lib)

        start=moment(start).format('YYYY-MM-DDTHH:mm:ssZ'); 
        end=moment(end).format('YYYY-MM-DDTHH:mm:ssZ'); 
Run Code Online (Sandbox Code Playgroud)