PHP: How to use IntlDateFormatter for local month names

Here’s how to get PHP to output a date with a full local month name.

setlocale(LC_ALL, 'no_NB.utf-8', 'nor'); // For other stuff
Locale::setDefault('no_NB.utf-8'); // For IntlDateFormatter

$f = new IntlDateFormatter(null, null, null, null, null, 'd. MMMM y');
echo $f->format(new DateTime("2013-01-01"));

// Outputs: 1. januar 2013

In this case I just use a hardcoded norwegian long date format, but check out the IntlDateFormatter constructor and you will find various date and time constants for various formats.

Note: Requires PHP version >= 5.3 and the extension active. If on Dreamhost you can do this by adding the following to your ~/.php/5.3/phprc

extension =