I am working in React and I have an array of data called this.state.candidate
and I am currently mapping the information to display it in a data table. One of the parameters item.updated_at
is formatted as "2019-08-06 13:52:43"
. I want to be able to convert this time to something like this "8/6/2019, 1:52:43 PM"
. How would I work around doing this. From my understanding this is possible by doing the following, although I'm not sure how to incorporate it into my code.
var date = new Date("2019-08-06 13:52:43");
date.toLocaleString(); // "8/6/2019, 1:52:43 PM"
This is a snippet of the code that I have:
const dataTable = this.state.candidate.map((item) => {
return {
id: item.id,
name: item.name,
current_company_name: item.current_company_name,
job: item.job_title,
owner: item.owner.name,
updated: item.updated_at,
email: item.email,
phone: item.phone,
is_active: item.is_active,
is_snoozed: item.is_snoozed,
};
});