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

213
Views
How to fix 'Invalid date' on IOS using native Date object or using date-fns?

I have an issue related to rendering date of content within my react application. I've got a date in a format '2021-11-24 20:17:39' from back-end, then I transformed it using the following function:

const getDate = (myDate) =>  
   new Date(myDate).toLocaleDateString(navigator.language, {
   month: 'short',
   day: 'numeric',
   year: 'numeric', 

as a result I got proper date format on every browser on my laptop, like Nov 24, 2021, but the issue was that on IOS I got 'Invalid date' instead of the date I need. Later on, I changed my approach and used the following code:

import { intlFormat } from 'date-fns';

    const getDate = (date) => {
       const userLocale =
       navigator.languages && navigator.languages.length
         ? navigator.languages[0]
         : navigator.language;
    return intlFormat(
       new Date(date),
      {
        month: 'short',
        day: 'numeric',
        year: 'numeric',
      },
     {
        locale: userLocale,
     }
   );
 };

So now the page crushes every time I open it (on IOS) Any ideas would be helpful! p.s. I need exactly this format as a result: Nov 24, 2021. And depending on user browser's location

about 4 years ago · Juan Pablo Isaza
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!