strtotime With Different Languages? strtotime With Different Languages? php php

strtotime With Different Languages?


French month dates are:

janvier février mars avril mai juin juillet août septembre octobre novembre décembre

Hence, for the very specific case where months are in French you could use

function myStrtotime($date_string) { return strtotime(strtr(strtolower($date_string), array('janvier'=>'jan','février'=>'feb','mars'=>'march','avril'=>'apr','mai'=>'may','juin'=>'jun','juillet'=>'jul','août'=>'aug','septembre'=>'sep','octobre'=>'oct','novembre'=>'nov','décembre'=>'dec'))); }

The function anyway does not break if you pass $date_string in English, because it won't do any substitution.


As mentioned strtotime does not take locale into account. However you could use strptime (see http://ca1.php.net/manual/en/function.strptime.php), since according to the docs:

Month and weekday names and other language dependent strings respect the current locale set with setlocale() (LC_TIME).

Note that depending on your system, locale and encoding you will have to account for accented characters.


This method should work for you using strftime:

setlocale (LC_TIME, "fr_FR.utf8"); //Setting the locale to French with UTF-8echo strftime(" %d %h %Y",strtotime($date));

strftime