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

216
Views
date-fns.format() is not working in safari browser

I am using the date-fns npm package for some date utility. Everything is working fine in the chrome browser. but in mac-safari it's not working. Here is my code snap...

const format = require('date-fns/format');
const parseISO = require('date-fns/parseISO');

const startDateInput = "2020-11-20T09:30:00.000Z";

const formattedStartDate = new Date(format(parseISO(startDateInput), 'MM-dd-yyyy'));
const formattedTodayDate = new Date(format(new Date(), "yyyy-MM-dd"))

console.log('formattedStartDate', formattedStartDate);//IN MAC SAFARI --> Invalid Date 
console.log('formattedTodayDate date1', formattedTodayDate);//IN MAC SAFARI --> Invalid Date 

The same console in chrome is giving Fri Nov 20 2020 18:30:00 GMT+0530 (India Standard Time) a valid date.

Not getting what is the issue with safari browser?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you don't need the format function if you just want a Date(), and you don't need to do new Date() either

This should work :

const startDate = parseISO(startDateInput);

Now you should have a valid Date object since date-fns will handle the ISO 8601 for you

if you want to format it :

const formattedStartDate = format(startDate, 'yyyy-MM-dd')

Here you have a date string, like 2022-05-05, you should just keep it as a string, use it where you need and you should not use it with new Date() because it will not work in safari

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!