Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!