jquery - fullcalendar.formatdate 不起作用

标签 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');
},

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

最佳答案

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

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 函数时,您应该查看网络浏览器控制台日志。您可能会看到:

Uncaught TypeError: undefined is not a function

这是因为 fullCalendar V2 ( changeLog ) 上不再存在 $.fullCalendar.formatDate 方法。 您可以将 Moment.js.format() 方法 ( doc ) 结合使用。

不要忘记导入 moment.js 并将 startend 变量编辑为:

start=moment(start).format('YYYY/MM/DD');
end=moment(end).format('YYYY/MM/DD');

它应该可以解决您的问题。

关于jquery - fullcalendar.formatdate 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24729721/

相关文章:

jquery - 获取最大ID

jquery - 如何在 JQuery 代码中添加延迟

javascript - Fullcalendar 通过 ajax 传递事件数据产生错误

jquery - 第一次尝试时无法从完整日历中删除事件

javascript - 为什么我会获得这种奇怪的行为,试图为拖动到 PrimeNG FullCalendar 组件中的不同事件类型使用不同的颜色?

javascript - $_FILES 在使用 HTML Form 和 Dropzone JS 时返回空

javascript - 当我想消失源拖动项目时如何停止消失?

javascript - AddThis:Facebook 共享忽略共享配置

javascript - 在全日历日 View 中显示超过 1 天

jquery - 使用 ASP.NET MVC 的 FullCalendar 中的 DateTimeOffset