Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting nominative month name in date-fns

How can I get the name of the month in nominative format?

import { format } from 'date-fns'; 
import { ru } from 'date-fns/locale';

format(new Date(), 'MMMM', { locale: ru }); // июня

How can I get the name like юинь instead of июня?

like image 334
Roman Mahotskyi Avatar asked Dec 05 '25 08:12

Roman Mahotskyi


2 Answers

I was able to find a solution. To get the stand-alone name of the month the LLLL format should be used.

The working code should look like this:

import { format } from 'date-fns'; 
import { ru } from 'date-fns/locale';

format(new Date(), 'LLLL', { locale: ru }); // июнь

See documentation -> Month (stand-alone): https://date-fns.org/v2.14.0/docs/format

like image 52
Roman Mahotskyi Avatar answered Dec 07 '25 20:12

Roman Mahotskyi


There are a few patterns you can use.

  • LLL: Jan, Feb, ..., Dec
  • LLLL: January, February, ..., December
  • LLLLL: J, F, ..., D
  • MMM: Jan, Feb, ..., Dec
  • MMMM: January, February, ..., December
  • MMMMM: J, F, ..., D
like image 22
Rafayel Avatar answered Dec 07 '25 20:12

Rafayel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!