Date joomla get input设置日历标记中的日期格式

Date joomla get input设置日历标记中的日期格式,date,joomla,calendar,formatting,components,Date,Joomla,Calendar,Formatting,Components,我的joomla组件中有一个日历输入框。日历元素的XML为: <field name="dob" type="calendar" label="COM_OPTICAL_DATABASE_FORM_LBL_PATIENTDETAIL_DOB" description="COM_OPTICAL_DATABASE_FORM_DESC_PATIENTDETAIL_DOB" format="%d-%m-%Y"

我的joomla组件中有一个日历输入框。日历元素的XML为:

        <field name="dob" type="calendar"

        label="COM_OPTICAL_DATABASE_FORM_LBL_PATIENTDETAIL_DOB"
        description="COM_OPTICAL_DATABASE_FORM_DESC_PATIENTDETAIL_DOB" 
        format="%d-%m-%Y"    


        filter="raw" /> 

具有正确的日期格式。但是,表单中的输入框显示为

Y-m-d

我想把它重新格式化到正确的日期

我找到了这个,它输入了当前日期:

                <div class="tablecol1 zebra1">
                     <?php echo $this->form->getLabel('dob'); ?>:&nbsp;&nbsp;
                </div>
                <div class="tablecol2 ">
                    <?php echo $this->form->getInput('dob', '', date('d-m-Y')); ?>

:  
但我希望它输入我从数据库检索到的日期。

请尝试以下操作:

<?php 
   echo $this->form->getInput('dob', '', JFactory::getDate('dob')->format('d-m-Y')); 
?>

或:



请注意,我还没有测试过它,所以请告诉我它是否有效,因为似乎没有人知道答案。我认为Joomla要么不允许这样做,要么在文档的某个地方有这样做的方法。不管怎么说,对于其他努力实现这一目标的人来说:

 <?php
 $birthDate1 = $this->form->getValue('dob');
 $birthDateHolder = explode("-", $birthDate1);
 $changed = $birthDateHolder[2]."-".$birthDateHolder[1]."-".$birthDateHolder[0];
 echo $this->form->getInput('dob', '', $changed); 
 ?>


我已经对此进行了测试,它工作正常。

这会引发500个错误DateTime::\uu construct()[DateTime.-construct]:无法分析时间字符串
 <?php
 $birthDate1 = $this->form->getValue('dob');
 $birthDateHolder = explode("-", $birthDate1);
 $changed = $birthDateHolder[2]."-".$birthDateHolder[1]."-".$birthDateHolder[0];
 echo $this->form->getInput('dob', '', $changed); 
 ?>