drnpwmq4536 2017-04-17 11:51
浏览 50
已采纳

DateTime从FullCalendar转换为Controller PHP

I'm using FullCalendar to display a calendar on the web page (no surprise there).
A user can add events on the calendar, which is then passed through POST to the CodeIgniter controller. The controller executes a function in the model to insert the data in the database.

The problem I'm facing is that the date time, when inserted in the database adds 4 minutes for a reason i do not understand.

This is the JavaScript used for FullCalendar:

$(document).ready(function() {
    var today = moment().day();
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        editable: true,
        defaultView: 'agendaWeek',
        eventLimit: true, // allow "more" link when too many events
        selectable: true,
        selectHelper: true,
        select: function(start, end) {
            var title = "<?=$anim['NOMANIM']?>";
            var id = "<?=$anim['CODEANIM']?>";
            if (title) {
                start   =   moment(start).format('YYYY-MM-DD HH:mm:ss');
                end     =   moment(end).format('YYYY-MM-DD HH:mm:ss');
                $.ajax({
                    url: '<?php echo base_url("index.php/activite/add_activite"); ?>',
                    data: 'title='+ title+'&id='+ id+'&start='+ start +'&end='+ end,
                    type: "POST",
                    success: function(json) {
                        alert(start); // THIS SHOWS THE CORRECT DATETIME
                    }
                })
            };
            $('#calendar').fullCalendar('renderEvent',
            {
                title: title,
                start: start,
                end: end,
            }, true); // stick? = true
            $('#calendar').fullCalendar('unselect');
        },
        events: <?=$events?>
    });
});

And here is the controller function:

public function add_activite() {
    $title = $_POST['title'];
    $id = $_POST['id'];

    $datetime_start = strtotime($_POST['start']);
    $datetime_end   = strtotime($_POST['end']);

    $date   = date('Y-m-d', $datetime_start);
    $start  = date('H:m:s', $datetime_start);
    $end    = date('H:m:s', $datetime_end);
    $this->EZ_query->insert_activite($date, $start, $end);
}

If you think there is something I'm doing not correctly beside the time problem, I'm open to any pointers :), Thanks!

  • 写回答

1条回答 默认 最新

  • duanpo1498 2017-04-17 11:55
    关注

    Your data formatting in php is not correct, minutes are denoted by i not m (which is used my month already). See here: http://php.net/manual/en/function.date.php

    So change:

    $start  = date('H:i:s', $datetime_start);
    $end    = date('H:i:s', $datetime_end);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛