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

183
Visualizações
Is there a way to reverse a format in date-fns?

I am from Thailand, and wondering is there a way to reverse a format in date-fns?

For example, this function will turn "2022-09-24" to "saturday-24-september-2564"

This there a good method using date-fns to create a new function that will turn "saturday-9-september-2564" back to "2022-09-24"?

Thank you so much in advance

//----------------

import format from "date-fns/format";
import th from "date-fns/locale/th";
import addYears from "date-fns/addYears";

const transformDate = (d) => {
        const newDate = new Date(d);
        const year_ymd = addYears(newDate, 543);

        const urlText =
          format(newDate, "EEEE'-'d'-'MMMM") + format(year_ymd, "'-'yyyy");

        return urlText.toLowerCase();
      };

transformDate(2022-09-24);
almost 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Just the other way around it would be something like this if I'm not mistaken:

import {format, addYears, parse} from "date-fns";
import {th} from "date-fns/locale/th";

const transformDate = (d) => {
        const newDate = new Date(d);
        const year_ymd = addYears(newDate, 543);

        const urlText =
          format(newDate, "EEEE'-'d'-'MMMM") + format(year_ymd, "'-'yyyy");

        console.log(urlText.toLowerCase());
      };

transformDate('2022-09-24');

const transformDate2 = (d) => {
  const parsed = parse(d, "EEEE'-'d'-'MMMM'-'yyyy", new Date(), { locale: th })
  const formatted = format(parsed, 'dd-MM-yyyy');
  console.log(formatted)
}

transformDate2('saturday-24-september-2565')

Also, 4th param in the parsemethod contains optional properties that could be passed. In case you need anything more feel free to refference this picture:

enter image description here

almost 4 years ago · Santiago Trujillo 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