日期格式指法问题

时间:2013-07-01 13:26:47

标签: php javascript jquery sql-server handsontable

我有一个简单的表格:     

                $("#old_tab_handsontable").handsontable({
                    data: data,
                    startRows: 1,
                    colHeaders: ['ID', 'datePers', 'dateArchive', 'dateAncienne', 'dateDef', 'IS'],
                    columns: [
                        {data: 'ID'},
                        {data: 'datePers', type: 'date'},
                        {data: 'dateArchive', type: 'date'},
                        {data: 'dateHist.old', type: 'date'},
                        {data: 'dateDef', type: 'date'},
                        {data: 'IS'}
                    ],
                    colWidths: [100, 100, 100, 100, 100, 100]
                });
    
所有通道都与我的数据库一起完成。我有一个按钮可以保存车道上的变化:     
        $("#save").click(function() {
            var handsontable = $("#old_tab_handsontable").data('handsontable');
            console.log(handsontable.getData());
            $.ajax({
                url: "/Reporting/saveperspective",
                data: {'data': handsontable.getData()},
                type: 'POST',
                success: function() {
                    generateJsMessage("Les perspectives ont bien été modifiées", 'success');
                },
                error: function() {
                    generateJsMessage("Une erreur s'est produite", 'error');
                }
            });
        });
    

我的问题是如果我将一个日期保存为2012-02-01,当我将重新加载页面时,所考虑的单元格将显示2012-01-02。当我在console.log(handsontable.getData());它仍然是2012-02-01,当我var_dump($ _ POST ['data'])时,它仍然是2012-02-01 ...... 我的数据库(我不允许触摸/修改/ ...)在SQL Server上。

我的更新控制器是:     

        public function saveperspectiveAction() {
            $this->_helper->getHelper('layout')->disableLayout();
            $this->_helper->viewRenderer->setNoRender();
            $data = $_POST['data'];
            _dump($_POST['data']);
            foreach ($data as $one):
                $this->reporting->updateListPerspectives($one['ID'], $one['datePers'], $one['dateArchive'], $one['dateDef'], $one['IS']);
            endforeach;
            return true;
        }
    

我的吸气控制器是     

     public function getperspectiveAction() {
            $resultSql = $this->reporting->getListPerspectives();
            $this->_helper->getHelper('layout')->disableLayout();
            $this->_helper->viewRenderer->setNoRender();
            $tab = array();
            foreach ($resultSql as $oneline) {
                if ($oneline['dateHist.old'] == NULL) {

array_push($tab, array('ID' => $oneline['theDate_id'], 'datePers' => $oneline['datePers']->format('Y-m-d'), 'dateArchive' => $oneline['dateArchive']->format('Y-m-d'), 'dateHist.old' => " ", 'dateDef' => $oneline['dateDef']->format('Y-m-d'), 'IS' => $oneline['isCriteria'])); } else { array_push($tab, array('ID' => $oneline['theDate_id'], 'datePers' => $oneline['datePers']->format('Y-m-d'), 'dateArchive' => $oneline['dateArchive']->format('Y-m-d'), 'dateHist.old' => $oneline['dateHist.old']->format('Y-m-d'), 'dateDef' => $oneline['dateDef']->format('Y-m-d'), 'IS' => $oneline['isCriteria'])); } } print json_encode($tab); } </pre>

1 个答案:

答案 0 :(得分:1)

尝试设置日期格式:

            $("#old_tab_handsontable").handsontable({
                data: data,
                startRows: 1,
                colHeaders: ['ID', 'datePers', 'dateArchive', 'dateAncienne', 'dateDef', 'IS'],
                columns: [
                    {data: 'ID'},
                    {data: 'datePers', type: 'date', dateFormat: 'mm/dd/yy'},
                    {data: 'dateArchive', type: 'date', dateFormat: 'mm/dd/yy'},
                    {data: 'dateHist.old', type: 'date', dateFormat: 'mm/dd/yy'},
                    {data: 'dateDef', type: 'date', dateFormat: 'mm/dd/yy'},
                    {data: 'IS'}
                ],
                colWidths: [100, 100, 100, 100, 100, 100]
            });