[英]how to convert datetime from mysql to doctrine2 odm in zf2?
i used doctrine2 Odm in zf2 but my update query store wrong result of date how i set date format in doctrine2 Odm? 我在zf2中使用了doctrine2 Odm但是我的更新查询存储错误的日期结果如何在doctrine2 Odm中设置日期格式? here is my update query:
这是我的更新查询:
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()));
}
but it stores begin=1970-01-01 05:33:34 and end=1970-01-01 05:33:34,how i store correct date format like 6/19/2014 6:33:00 AM? 但它存储开始= 1970-01-01 05:33:34和结束= 1970-01-01 05:33:34,我如何存储正确的日期格式,如6/19/2014 6:33:00 AM?
You need to use 你需要使用
->field('begin')->set(new \DateTime($post['begin']))
Doctrine will format the data the right way. Doctrine将以正确的方式格式化数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.