Vikram Vikram - 6 months ago 21
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

<?php
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
?>


UPDATE

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
enero
into
ene
like short hand?

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

Answer

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.

Try:

setlocale(LC_TIME, 'es_ES', 'Spanish_Spain', 'Spanish');  
Comments