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

224
Views
How to properly convert ISO date to MM/DD/YYYY

I have a date coming back in this format 2021-12-03T00:00:00.000Z which I then convert to an ISO date string and then construct a new Date() based on the split ISO string. The issue is that my date properly gets formatted with every month except December. Anytime I pass a December date, the logic always converts it to be January of the next year.

Code

//bill.date_paid at this point = '2021-12-03T00:00:00.000Z'

let isoDateString = new Date(bill.date_paid).toISOString().split('T')[0].split('-');

//isoDateString = ['2021', '12', '03'];

bill.date_paid = new Date(isoDateString[0], isoDateString[1], isoDateString[2]).getTime();

//date conversion above = 1641193200000 which is equal to a January date... 

But why?

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

0

To convert your iso date to the mm/dd/yyyy format you can use a Intl.DateTimeFormat object like below :

const date = new Date('2021-12-03T00:00:00.000Z');
const result = new Intl.DateTimeFormat('en-US').format(date);
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Why you don't convert it directly to time?

let date_paid = '2021-12-03T00:00:00.000Z'
let date = new Date(date_paid).getTime()
console.log(date)

about 4 years ago · Juan Pablo Isaza Report

0

You can try this

date = new Date('2021-12-03T00:00:00.000Z');    
console.log((date.getMonth()+1)+'/'+(date.getDate()) + '/'+date.getFullYear());

Also you can use moment.js

console.log(moment(new Date('2021-12-03T00:00:00.000Z')).format("MM/DD/YYYY"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

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!