I have a set of data, it was returned from the backend, and from this data there is a date and the date was returned in the form:
2022-02-01T01:00:00.000Z
But the problem is that I want the date to be in the form:
2015/04/25 02:07:59
how can i solve the problem?
this is the code:
<td>
<span className="truncate">{order.salary.workStartDate}</span>
</td>
CodePudding user response:
Just pass the DB response as a string into the new Date(dateFromDB)
constructor and you can do whatever you need with your new date object.
// for example
const d = new Date("2022-02-01T01:00:00.000Z");
const yyyymmdd = `${d.getFullYear()}-${d.getMonth() 1}-${d.getDate()}`;
console.log(yyymmdd); // 2022-1-31
CodePudding user response:
var string = "2022-02-01T01:00:00.000Z"
var date = new Date(string)
console.log(date.toLocaleString()) // 2/1/2022, 2:00:00 AM