Vikram Vikram - 2 years ago 119
PHP Question

Trying to display a date in Spanish

Nothing is working for me. Here is the code snippet I tried

$oldLocale = setlocale(LC_TIME, 'it_IT');
echo strftime("%a %d %b %Y", $row['eventtime']);
setlocale(LC_TIME, $oldLocale);

I have also tried this

setlocale(LC_ALL, 'it_IT');
$originalDate = "04/01/2014";
$originalDate =date("d/m/Y", strtotime($originalDate));
$newDate = date("d M Y", strtotime($originalDate));
echo $newDate


I tried this code

setlocale(LC_TIME, 'es_ES', 'Spanish_Spain', 'Spanish');
$date = $date = str_replace("/","-","04/01/2014");
echo strftime('%d %B %Y',strtotime($date));

So now it's showing
04 enero 2014
but is there a way I can make
like short hand?

Both the code are showing date in English only. Any help would be appreciated.

Answer Source

You really ought to set your locale in php.ini, not dynamically.

And, it_IT is an Italian locale not a Spanish one.

You want the strftime() method in the first code snippet.

Finally, locale names are different on different operating systems.


setlocale(LC_TIME, 'es_ES', 'Spanish_Spain', 'Spanish');  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download