Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
Format date with date-fns

Am trying to format date with such an example 2021-09-20T12:12:36.166584+02:00 with date-fns library but it doesn't work, what's the right approach ?

Below is my code :

import { format } from 'date-fns'
format(date, 'DD.MM.YYYY')
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You have to parse your ISO string before you can format it, and use lowercase dd and yyyy:

import { format, parseISO } from "date-fns";

const dateFormatted = format(parseISO(date), "dd.MM.yyyy");
about 4 years ago · Juan Pablo Isaza Denunciar

0

We definitely need more information on what the problem is.

But I guess you want to have a day of the month to be formatted so you should put dd instead of DD.

DD = 01, 02, ..., 365, 366

dd = 01, 02, ..., 31

And yyyy instead of YYYY.

And your input param date should be a type of Date:

format(new Date('2021-09-20T12:12:36.166584+02:00'), 'dd.MM.yyyy')

Everything can be found in documentation (https://date-fns.org/v2.24.0/docs/format)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda