How to convert a date in string to ISO format in JavaScript

1 Answer

0 votes
const s = '23/03/2022';
 
const [day, month, year] = s.split('/');
 
const date = new Date(+year, +month - 1, +day);
 
const iso = date.toISOString();
 
console.log(iso);
 
   
   
   
   
/*
run:
   
"2022-03-22T22:00:00.000Z"
   
*/

 



answered Mar 23, 2022 by avibootz
edited Apr 3, 2022 by avibootz

Related questions

...