Matt Ryan
Matt Ryan

Reputation: 39

Changing date format to a specific format in JavaScript

In my application I have date coming in an ISO String format: '2020-12-20T15:21:28.411Z' In the database the value is stored as: '2020-12-20 15:21:28+411'.

So how can I convert '2020-12-20T15:21:28.411Z' -> '2020-12-20 15:21:28+411'.

I don't want to use moment.js and .toLocaleString() does not work.

Upvotes: 2

Views: 40

Answers (1)

Wais Kamal
Wais Kamal

Reputation: 6180

Assuming your date is in the string format, you can replace the dot with a + and the T with a space, then chop off the last character:

yourDate.replace(/\./g,"+").replace(/T/g," ").slice(0,-1)

Upvotes: 1

Related Questions