我正在尝试做一些聪明的事情,以便解析任何国际格式的日期。
在我的前端,我使用 jquery ui 作为日期选择器,每种语言都有其特定的日期格式。
Fr:日/月/年
En:月/日/年
...
好的,但现在在 php 部分我必须使用相同的格式(Mysql Y-m-d)存储这些日期。我想避免使用开关盒和类似的东西,所以我开始寻找另一种选择。
我发现的最好的事情是
http://www.php.net/manual/en/datetime.createfromformat.php http://www.php.net/manual/en/datetime.createfromformat.php如果我知道格式,该函数将使我能够解析日期。
例如
$format = 'Y-m-d';
$date = DateTime::createFromFormat($format, '2009-02-15');
好的,这是一个好的开始,但现在我想找到当前区域设置的标准日期格式。
所以我发现了这个:
http://www.php.net/manual/en/intldateformatter.getpattern.php http://www.php.net/manual/en/intldateformatter.getpattern.php
但我真的不知道如何让它发挥作用,因为我得到的结果不一致:
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 */
我错过了什么吗?
Thanks