I'm trying to make something clever in order to parse date in any international format.
On my frontend I use jquery ui as a date picker and each languages has its specific date format.
Fr: d/m/Y En: m/d/Y ...
OK but now on the php part I have to store those date using the same format (Mysql Y-m-d). I would like to avoid using switch case and stuff like that so I started to look for another alternative.
The best thing I've found is
http://www.php.net/manual/en/datetime.createfromformat.php That function will enable me to parse the dates if I know the format.
For example
$format = 'Y-m-d';
$date = DateTime::createFromFormat($format, '2009-02-15');
Ok so that's a good start but now I'd like to find the standard date format for the current locale.
So I found this :
http://www.php.net/manual/en/intldateformatter.getpattern.php
But I dont really know how to get it to work because I get inconstitent results:
php > $i = new IntlDateFormatter("fr_FR.utf8",IntlDateFormatter::SHORT,IntlDateFormatter::NONE);
php > echo $i->getPattern();
dd/MM/yy
/* correct ! */
but
php > $i = new IntlDateFormatter("en_US.utf8",IntlDateFormatter::SHORT,IntlDateFormatter::NONE);
php > echo $i->getPattern();
M/d/yy /* wtf */
Am I missing something ?
Thanks