1

I am trying to change an ISO date to a Standard JS Date format. The JS format I am referring to is:

Mon `Jul 20 2020 14:29:52 GMT-0500 (Central Daylight Time)`

What is the best way to go about doing this? Thanks!

2 Answers2

1

const ISO_DATE = '2020-07-14T23:02:27.713Z';

function formatDate(dateStr) {
  const date = new Date(dateStr);
  
  return date.toString();
};

console.log(formatDate(ISO_DATE));
JBallin
  • 8,481
  • 4
  • 46
  • 51
1

One way is:

let isoDate = "2020-07-20T14:29:52Z";
var myDate = new Date(isoDate);

console.log(myDate.toString());   // Mon Jul 20 2020 17:29:52 GMT+0300 ( (your time zone)

console.log("Back to ISO Date: ", myDate .toISOString());

If you want to convert it back to ISO Date use:

console.log(myDate.toISOString());

Mohsen Alyafei
  • 4,765
  • 3
  • 30
  • 42