-2

I am getting date in this format 01/01/2022 (dd/mm/yyyy). And i have to convert it into ISO format("2022-01-01T00:00:00.000+01:00"). I've tried but I get invalid time value error.

const newDate ='01/01/2022' 
"2022-01-01T00:00:00.000+01:00"
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
Abhigyan Gaurav
  • 1,854
  • 6
  • 28
  • 58

1 Answers1

1

try this

var str = "25/09/2019";
darr = str.split("/");    // ["25", "09", "2019"]
var ISOFormat = new Date(parseInt(darr[2]),parseInt(darr[1])-1,parseInt(darr[0]));

console.log(ISOFormat.toISOString());

also refer this link by mozilla