Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
Localize date-fns

I had a working solution for date-fns using the following:

const formatMonth = format("MMM");

Then I imported the locale and tried the following:

import { de } from 'date-fns/locale';

const formatMonth = format("MMM", {locale: de});

Getting the error: RangeError: Invalid time value. How do I change the language to german? The docs kinda suggest exactly the same, but it's not working.

EDIT: Maybe that is relevant and showcases, why the new Date() is not necessary for the format:

const months = eachMonthOfInterval({
    start: startOfYear(value),
    end: endOfYear(value)
});
{months.map((month) => (
   <ListboxOption
     key={month.toDateString()}
     value={month}
     date={formatMonth(month)}
     disabled={!isOlderThen18Years(month)}
   ></ListboxOption>
))}

Also, this code works in code sandbox, but won't in my react application. Still throwing an error: RangeError: Invalid time value.

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

const date = new Date();

console.log( format(
  date, 'MMM', 
{ awareOfUnicodeTokens: true, locale: de}
) );
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As you are using the FP version to format a date you need to use the formatWithOptions function to pass the locale options.

import format from "date-fns/fp/formatWithOptions";

It has a slightly different function signature then the format function, where you need to pass the options as the first argument.

const formatMonth = format({ locale: de }, "MMM");

Edit happy-hill-2e0mb

about 4 years ago · Juan Pablo Isaza Relatório

0

You need to pass the Date as the first Parameter. For an example,

const formatMonth = format(new Date(),"MMM", {locale: de}); <br>

OR

const formatMonth = format(new Date(10/28/2021),"MMM", {locale: de});

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda