我正在尝试更改ZF2应用程序中的日期格式。我试过这个:
$this->add(array(
'type' => 'Zend\Form\Element\Date',
'name' => 'date_of_entry',
'options' => array(
'label' => 'Datum unosa',
'format' => 'd-m-Y'
),
'attributes' => array(
'class' => 'my_input',
'min' => '01-01-1970',
'step' => '1',
)
));
$this->get('date_of_entry')->setFormat('d-m-Y');
在视图中我得到mm \ dd \ yyyy格式,出了什么问题?
答案 0 :(得分:2)
您无法在数组中设置格式 - 必须通过 setFormat()调用。
我认为您需要删除此'format' => 'd-m-Y'
$this->add(array(
'type' => 'ZendFormElementDateTime',
'name' => 'date_of_entry',
'options' => array(
'label' => 'Datum unosa',
),
'attributes' => array(
'class' => 'my_input',
'min' => '01-01-1970',
'step' => '1',
)
)
);
$this->get('date_of_entry')->setFormat('d-m-Y');
希望这对你有用。