簡體   English   中英

如何在zf2中將datetime從mysql轉換為doctrine2 odm?

[英]how to convert datetime from mysql to doctrine2 odm in zf2?

我在zf2中使用了doctrine2 Odm但是我的更新查詢存儲錯誤的日期結果如何在doctrine2 Odm中設置日期格式? 這是我的更新查詢:

if ($this->getRequest()->isPost()) {
                $post = $this->getRequest()->getPost();
                $form->setInputFilter($form->getInputFilter());
                $form->setData($post);
                //echo '<pre>';
                //print_r($post);
                //die();
                if($form->isValid())
                {
                    $formData=$form->getData();
                    $update=$dm->createQueryBuilder('Calendar\Document\Event')
                    ->update()
                    ->field('title')->set($post['title'])
                    ->field('description')->set($post['description'])
                    ->field('begin')->set(date('Y-m-d H:i:s', $post['begin']))
                    ->field('end')->set(date('Y-m-d H:i:s', $post['end']))
                    ->field('id')->equals($id)
                    ->getQuery()
                    ->execute();

                    return $this->redirect()->toRoute('calendar');
                    //return $this->redirect()->toRoute('calendar', array('action' => 'show', 'id' => $form->get('calendar_id')->getValue()));

                }

但它存儲開始= 1970-01-01 05:33:34和結束= 1970-01-01 05:33:34,我如何存儲正確的日期格式,如6/19/2014 6:33:00 AM?

你需要使用

->field('begin')->set(new \DateTime($post['begin']))

Doctrine將以正確的方式格式化數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM