Search code examples
javascriptdate-fns

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


Solution

  • 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