On Wed, 15 Sep 2004 22:57:56 -0700, Mark D. Anderson wrote
> Am I correct that the only way to map the number 12 to "Dec"
> is this mouthful:
> 
> # DateTime constructor produces an error if only month is supplied.
> substr(new DateTime(year => 2004, month => 12)->month_name(), 0, 3);
> 
> -mda


Try one of these:

1. If you have a datetime object already set to the required locale (default 
is en_US) you could use it's locale. This could look confusing as the result 
has nothing to do with the object itself:

    print $dt->locale->month_abbreviations->[ $month_number - 1 ];

2. Otherwise you can use a DateTime::Locale object:

    use DateTime::Locale;
    my $en = DateTime::Locale->load('en')
    print $en->month_abbreviations->[ $month_number - 1 ];

Using the locale's abbreviation is so much better than substr-ing the 
month_name. There are some (many?) languages that don't use the first three 
letters for the abbreviation.

Cheers!
Rick Measham




Reply via email to