我正在使用 Zend 和 Doctrine 并使用 jquery 日历以 dd/mm/yyyy 格式收集日期。我需要将其格式化为 yyyy/mm/dd 进入 MySql。
我最近开始使用 Zend 和 Doctrine,所以不确定应该在哪里以及如何完成这种格式化。有人可以帮助我吗?
最佳答案
我建议你使用 jquery-datepiker 将这种可能性与意大利本地化一起使用,以便将日历设置为意大利语,但要设置格式 datepiker yyyy-mm-dd 所以我可以毫无问题地将它保存在数据库中在数据中进行任何更改。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/i18n/jquery.ui.datepicker-it.js"></script>
//DatePicker
$('.inputDate').datepicker({
dateFormat: 'yy-mm-dd'
});
或
现在我想到,如果你坚持你的选择,你可以使用 Doctrine 的行为:http://www.doctrine-project.org/blog/using-behaviors-to-share-relationship-properties
查看示例设置密码。
你可以这样实现:
class NameModel extends BaseNameModel
{
public function setDate_name($date_name)
{
list($d, $m, $y) = explode("-", $date_name);
$newDateName = $y."-".$m."-".$d;
$this->_set('date_name', $newDateName);
}
}
关于php - Zend 和 Doctrine 的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7647145/