用法语将字符串转换为时间 - PHP

时间:2014-05-22 08:45:20

标签: php date

基本上我想将任何看似012014的字符串更改为Janvier 2014 用法语。 所以我试过这个,但没有一个有效!

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

相反它会显示我May2014,它是显示当前月份的原因,为什么会这样?它是如何用法语显示的?

非常感谢!

1 个答案:

答案 0 :(得分:3)

我建议您使用DateTime Class(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 documentation

如果仍然无效,请检查是否存在给定的区域设置:

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