将字符串转换成时间在法语- PHP



基本上我想改变任何字符串看起来像这个012014Janvier 2014在法国。所以我尝试了这个,没有一个工作!

 date_default_timezone_set('Europe/Paris');
 setlocale(LC_TIME, "fr_FR");
 $pubdate = date('MY', strtotime('012014'));
 echo $pubdate;

相反,它显示我May2014,它是显示我当前月份,为什么?用法语怎么显示呢?

感谢!

我建议您使用DateTime类(PHP 5>= 5.2.0),然后使用strftime使用给定的区域设置输出日期

// Set the locale to French
setlocale(LC_TIME, "fr_FR");
// Create a date object from your format
$date = DateTime::createFromFormat('mY', '042014');
// Format the date according to locale settings
strftime("%B %Y", $date->getTimestamp());

查看strftime文档中所有可用的格式

如果这仍然不起作用,检查给定区域设置的存在:

// Returns false if the locale is not available on your system
var_dump( setlocale(LC_TIME, "fr_FR") );

最新更新