I am doing a personal React.js project. I have a map that gives me as one of the values an Epoch timestamp. I want to display only the time of that timestamp as AM or PM, but I can't figure it out. This is the code:
import { useEffect, useState } from "react";
const Home = () => {
const [result, setResult] = useState([]);
useEffect(() => {
fetch("https://www.betright.com.au/api/racing/todaysracing")
.then((res) => {
return res.json();
})
.then(
(data) => {
setResult(data);
console.log("data useEffect", data);
},
(err) => {
return console.error(err);
}
);
}, []);
console.log("result", result);
return (
<>
<h1>Upcoming Racing</h1>
{Object.entries(result).map(([key, value]) => (
<table key={key}>
<thead>
<tr>
<th>{key}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{value.slice(0, 5).map((dog, c) => (
<div key={c}>
<div>Race name: {dog.Venue}</div>
<div>Race number: {dog.Race1.RaceNumber}</div>
<div>
Advertised date:
{Date(dog.Race1.AdvertisedStartTime.slice(6, 19))}
</div>
</div>
))}
</td>
</tr>
</tbody>
</table>
))}
</>
);
};
export default Home;
This is a codesandbox link with the whole code and its output.