Formatting Date in React Render

Hello;

Depending on how the API responds, the way you process and format the data will vary. But with that format you can use string time formatting inside to maping, for example, as shown below. Also, there’s no need to return again inside of mapping.

  const formattedStartTime = index.startTime.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });

Also if you don’t want to specific time format just for take to hour you can use this method too:

const date = new Date(index.startTime);
const hour = date.getHours();

Here is the related documentation to find what format do you want. There is pleanty method in there, toLocaleString is quite enough.

Happy coding.