2

I'm building an app using MERN stack, but using SQL Server rather than Mongoose. In my jsx file, I have this.

<tr key={order.orderid}>
<td>{order.Date}</td>

This is how it appears in the table

"2020-09-03T00:00:00.000Z"

How do I format that date to dd/mm/yyyy?

1 Answers1

2

You can use toLocaleString()

let date = new Date("2020-09-03T00:00:00.000Z")
console.log(date);
console.log(date.toLocaleString())

If you want it without time:

let date = new Date("2020-09-03T00:00:00.000Z")
console.log(date);
console.log(date.toLocaleString().split(' ')[0])

Another way without using Date object:

let date = "2020-09-03T00:00:00.000Z";
let splitted = date.split('T')[0].split('-')
console.log(splitted.reverse().join('/'))
sonEtLumiere
  • 4,461
  • 3
  • 8
  • 35