Getting nominative month name in date-fns

Viewed 14803

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 июня?

3 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

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
Related