Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

postitief's avatar

Date localization

Hello,

I've read several posts for getting the localization of dates correctly, but none seems to be working for me. So I'm asking again, how will I be able to display dates in my native language (Dutch in this case)? I'm running homestead.

What have I already tried:

My whole code:

setlocale(LC_TIME, 'nl_NL.utf8');
var_dump(Carbon::now()->format('l jS \\of F Y h:i:s A'));
var_dump(Carbon::now()->formatLocalized('l jS \\of F Y h:i:s A'));

This outputs:

string 'Thursday 23rd of April 2015 10:14:30 AM' (length=39)
string 'l jS \of F Y h:i:s A' (length=20)

I also tried this on top of my routes.php file.

Route::filter('SetLocaleFilter', function()
{
    $locale = "nl";
    setlocale(LC_ALL, strtolower($locale) . "_" . strtoupper($locale) . ".utf8");
});

I just don't understand it!

0 likes
7 replies
rjsworking's avatar
Level 2

Hi

It's working ok for me on homestead.

Installed the nl_NL locale and checked the available locales

setlocale(LC_TIME, 'nl_NL.utf8');
var_dump(\Carbon\Carbon::now()->addMonth()->formatLocalized('%d %B %Y'));

Result

string '23 mei 2015' (length=11)

Cheers

1 like
postitief's avatar

@rsdev000, Probably I wrongly formatted my string. Doing this is working perfectly now:

var_dump(\Carbon\Carbon::now()->formatLocalized('%d %B %Y'));
// string '23 april 2015' (length=13)

I know it's Dutch because of the lowercase month!

What would be the right place to put

setlocale(LC_TIME, 'nl_NL.utf8');

Thanks!

rjsworking's avatar

Hi

I would say that the right place is a middleware.

Cheers

ovvessem's avatar

Please be aware that some servers need the following setlocale syntax:

setlocale(LC_TIME, 'nl_NL.UTF-8');

or for all locales at once

setlocale(LC_ALL, 'nl_NL.UTF-8');

Please or to participate in this conversation.