Reputation: 628
Format the date in react component. I tried to call toLocaleDateString
, and other options, all to no avail. Either I didn’t receive any changes, either the error '.... is not a function'
The date component comes in this format:
2018-10-07T06:39:55.578686Z
Upvotes: 1
Views: 1565
Reputation: 4633
You can use new Date()
to do this. You won't need moment()
for this.
let d = "2018-10-07T06:39:55.578686Z"
let date = new Date(d);
let formattedDate = date.toDateString() //Or any other methods that date supports
console.log(formattedDate);
Upvotes: 1