The default datetime format in a symfony datetime field is yyyy-MM-dd HH:mm:ss
for my locale. This is not very user friendly so I'd like to change it to the long date format. I'm also using jquery datetimepicker after the page loads to assist users in choosing the correct date/time.
I can't seem to get the date formats to match up and have symfony consider the data that's passed back as a valid date.
Controller code for the form:
$form = $this->createFormBuilder($auction)
->add('endDate', DateTimeType::class, array(
'view_timezone' => $user->getTimeZone(),
'widget' => 'single_text',
'format' => \IntlDateFormatter::FULL
))
->add('save', SubmitType::class, array('label' => 'Create Auction', 'attr'=> array('class'=>'button primary')))
->getForm();
View code for the datetimepicker:
$(document).ready(function(){
$.datetimepicker.setDateFormatter({
parseDate: function(date, format){
var d = moment(date, format);
return d.isValid() ? d.toDate() : false;
},
formatDate: function(date, format){
return moment(date).format(format);
}
});
$("#form_endDate").datetimepicker({
format: 'dddd, MMMM D, YYYY h:mm:ssa',
formatDate: 'dddd MMMM D, YYYY',
formatTime: 'h:mm a'
});
});
I've also tried using the same text in the Controller to match the format in the datetimepicker initialization:
'format' => 'dddd, MMMM D, YYYY h:mm:ssa'
But that does not help. There is nothing in the logs either so I don't know how else to troubleshoot.
How do I get these formats to match so that the user entered input is valid?