L
L
lolrofl012021-05-13 15:19:15
PHP
lolrofl01, 2021-05-13 15:19:15

How to incline month in Carbon (datetime)?

I didn't find carbon in the documentation. It is necessary to display the months in the parent case (January, February, March ...). Carbon has this, the source lists an array with:

'months' => ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'],


However, I did not understand how to get them. I output like this:
Carbon::parse($post->created_at)->translatedFormat('F')
//или
Carbon::parse($post->created_at)->getTranslatedMonthName()

The result is the same: "January". How to display "January"? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-05-13
@lolrofl01

https://carbon.nesbot.com/docs/

$now = new \Carbon\Carbon();

$now->locale('ru');

$month = $now->getTranslatedMonthName('Do MMMM');

var_dump($now->day . ' ' . $month); //string(9) "13 мая"

UPD: well, there are more concise options, without concatenation, too lazy to fix, I think you'll figure it out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question