Converting ISO-8601 date format to JavaScript MM/DD/YYYY date format

Christian Kramp
Nov 26, 2022

--

Converting date formats is a pain for me. I often had a format like this: 2021–12–31T00:00:00.000Z

What is it? It’s ISO-8601. And not useful for my date inputs. And I spent hours to find a solution. But it’s very simple. Here’s how I did it:

var isodate = new Date("2021-12-31T00:00:00.000Z");
var localedateformat = isodate.toLocaleDateString('en-US');

What you’ll get is the following format: mm/dd/yyyy. This is the format for the US. You can also use others, like en-GB for the United Kingdom, ar-EG for the Arabic date format, or even he-IL for Hebrew.

Happy coding.

--

--