0

Basically I wangted to change any string that look like this 012014 into Janvier 2014 in french. So Itried this and none of them worked!

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

Instead it displays me May2014, is it that it display me the current month and why is that?And how to display it in french?

Much appreciated!

SpencerX
  • 5,453
  • 1
  • 14
  • 21
  • see also http://stackoverflow.com/questions/21430767/php-print-month-in-french?rq=1 http://stackoverflow.com/questions/5652443/how-to-get-php-to-use-internationalised-dates?rq=1 – John Carter May 22 '14 at 08:47
  • The main issue here I guess is that why it convert it to wrong date? – SpencerX May 22 '14 at 08:50

1 Answers1

3

I suggest you to use the DateTime Class (PHP 5 >= 5.2.0) then use strftime to output the date using a given locale

// 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());

Check the strftime documentation for all available formats

If this still don't work, check the presence of the given locale :

// Returns false if the locale is not available on your system
var_dump( setlocale(LC_TIME, "fr_FR") );
GuCier
  • 6,919
  • 1
  • 29
  • 36
  • Is the french locale installed on your system ? On osx / linux systems, you can check by running the terminal command : `locale -a` – GuCier May 22 '14 at 09:18