Monday, 1 October 2012

Translate date into your language

 i got a requirment wherein i user add date in US(English) format but user want to display spanish language/or Other Language.

First Method :


/* Windows con apache
setlocale(LC_TIME, 'Spanish'); */

/* Apache con linux */
/* setlocale(LC_TIME, 'es_ES'); */

// setlocale(LC_TIME, 'de_DE'); 
// echo strftime('%A, %d. %B %Y');  

/* setlocale(LC_TIME, 'es_MX'); */

setlocale(LC_TIME, 'es_ES'); //pase language code 
echo $fecha=strftime('%B %d %Y',strtotime('01-09-2012'));// Output septiembre 01 2012

Second Method 

function converttospanish($paramdate)
{
$str=$paramdate;
$month = array("","enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiempre", "diciembre");// you can change different language 
if (($timestamp = strtotime($str)) !== false)
{
$php_date = getdate($timestamp);
$dm = date_parse_from_format("Y-m-d", $paramdate);
echo $php_date["mday"].' '.$month[$dm["month"]].' '.$php_date["year"];
}
else
{
echo 'invalid timestamp!';
}
}


No comments:

Post a Comment