As per http://php.net/manual/en/class.datetime.php
PHP follows "ATOM" date format. To produce a date like "2017-11-14" we need date format string "Y-m-d". I am able to produce it using php date function and class. It works as expected.
/////Using date function////
echo date("Y-m-d");
/////Using DateTime class////
$date = new DateTime();
echo $date->format('Y-m-d');
Now I want to use these date formats dynamically in my Symfony3 application. As per docs, format for dateType field must be according to "RFC3339" because it uses IntlDateFormatter class for formatting. https://symfony.com/doc/current/reference/forms/types/date.html#format
So to produce date same as previous one, we need different format string
$date = new DateTime();
$dateFormat = new IntlDateFormatter(
"en_US",
IntlDateFormatter::NONE,
IntlDateFormatter::NONE,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'yyyy-MM-dd'
);
echo $dateFormat->format($date->getTimestamp());
To render datepicker fields on my forms, I am using bootstrap datepicker (https://bootstrap-datepicker.readthedocs.io/en/stable/options.html#format). Format demand to produce same previous date here is bit different "yyyy-mm-dd".
Although I can understand datepicker format can be different from PHP one. But I am unable to understand why there is difference between PHP and symfony date format requirements.
I am not sure how to make it working, as there can be plenty of formats, user can choose from. So a user chooses his date format preferences and I need to produce same date string everywhere.
I am thinking about some converter which can transform PHP date string to symfony and javascript formats or if I can manage to change dateformatter for symfony it can help also in my opinion.