I am trying to get the name of the month by passing the number of the month as a parameter to my function. I want it to appear in Spanish and I don't want to use the deprecated strftime function, I want to update my code to php 8 functions. I have been doing a lot of research and I have found the following:
$formatter = new \IntlDateFormatter(
'es_ES',
\IntlDateFormatter::LONG,
\IntlDateFormatter::LONG,
'Europe/Madrid'
);
return $formatter->format($mes);
but I don't know how I can pass the name of the month to IntlDateFormatter so that only September appears, for example.
I hope you can guide me a bit. I use native php, nothing from composer or external libraries
Thank you and regards
Two important points:
Get the date: for this I implement a relative format that it supports
DateTime
and that can be passed as a parameter toIntlDateFormatter
.Obtain the data with the expected format: what happens is that it
IntlDateFormatter
also supports formats, for example:Example:
Output:
Here is the documentation , exactly on the third example of the OOP version.
Implementation:
Creating a class that allows me to play and work dynamically with the data.