Laravel carbon get current month in dutch
Asked Answered
H

2

6

I'm trying to show the full current month name in dutch. I've tried it like this:

\Carbon\Carbon::now()->subMonth()->format('F')

But then I see July so not what I want. My app service provider looks like this:

public function boot()
{
    Carbon::setLocale('nl');
}

Any Idea what I could do to get this to work?

(diffForHumans is working correctly)

Hageman answered 17/7, 2017 at 7:28 Comment(7)
What you want as result ?Villatoro
@BibhudattaSahoo I want the dutch translation of a month. So instead of July I want Juni.Hageman
Not sure about this issue sorry, but I know of a good alternative package - which is based on Carbon, if you were interested: github.com/jenssegers/dateBreeder
@AareonFahey thanks that solved my problem!Hageman
@AareonFahey but it's not good I guess to pull in an entire package only to fix this :)Hageman
Other sources seem to suggest that you can also try setlocale(LC_TIME, 'nl'); in your service provider.Tomcat
@Hageman Not sure where you are from, but the Dutch translation for July is 'juli' not 'juni'Trickery
D
3

If you don't want to pull an entire package and want to only install your locale, then you could list the locale installed in your (linux) server by issuing the command

locale -a

If your locale isn't listed, then you may install your locale nl using the command

sudo locale-gen nl
sudo update-locale

then the usual setLocale

Drivein answered 17/7, 2017 at 7:45 Comment(0)
V
2

Just check class.intldateformatter.php

And try this

$fmt = new IntlDateFormatter(
    'nl_NL',
     IntlDateFormatter::GREGORIAN,
     IntlDateFormatter::NONE
);
echo $fmt->format(mktime(null, null, null, 1, 15, 2014));

// output: 15 januari 2014
Villatoro answered 17/7, 2017 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.