views:

260

answers:

2

I'd like to use Zend_Date to print out the previous 2 months and year as a string e.g.:

July 2009 June 2009

I need it to be locale aware so that if the code runs with the locale set to, say, German, the month names will print in German.

  $date = new Zend_Date();
    $date->subMonth(1);
    echo $date->get(Zend_date::MONTH_NAME).' '.$date->get(Zend_Date::YEAR);
    $date->subMonth(1);
    echo $date->get(Zend_date::MONTH_NAME).' '.$date->get(Zend_Date::YEAR);

Is this all I need to do?

thanks

+1  A: 

Specify the locale when creating the Zend_Date object. Like this:

$date = new Zend_Date(new Zend_Locale('de_AT'));
$date->subMonth(1);
echo $date->get(Zend_date::MONTH_NAME).' '.$date->get(Zend_Date::YEAR);
$date->subMonth(1);
echo $date->get(Zend_date::MONTH_NAME).' '.$date->get(Zend_Date::YEAR);
Mark
+2  A: 

You can just use the optional locale parameter in the get method:

$date = new Zend_Date();
echo $date->get(Zend_Date::MONTH_NAME,'de_DE');
echo $date->get(Zend_Date::MONTH_NAME,'en_UK');
Rufinus