-2

I am getting 2022-02-08T09:34:35.000Z this response from an API.

I am trying to convert it into a simple format like- 08-02-2022 09:34:35

amit yadav
  • 17
  • 2
  • 7

1 Answers1

-1

You can use the Date.prototype.toLocaleString()

let date = new Date();
date = date.toLocaleString()
arialdev
  • 51
  • 2
  • 6
  • If this is ran in the US the result would be 02-08-2022 not what the OP wants. – Liam Feb 08 '22 at 11:11
  • In fact, no, it wouldn't even be that it'd be `02/08/2022`, so this is **totally** wrong – Liam Feb 08 '22 at 11:13
  • @Liam I understand that if that is what he receives from the server he is getting it on the client. And this would return '2/8/2022, 12:08:34 PM'. What you mean is toLocaleDateString() – arialdev Feb 08 '22 at 11:26
  • *I am trying to convert it into a simple format like- 08-02-2022 09:34:35* `2/8/2022, 12:08:34 PM` is not `08-02-2022 09:34:35` – Liam Feb 08 '22 at 13:24