My API passes a datetime string like 2022-04-23T11:48:18.568507 into the code.
It can be parsed but when I try to getMinutes() or getHours() on it it doesn't work and gives an error:
TypeError: this is not a date object at Object.getHours()
How can I fix this? If you suggest moment.js can you tell me how to import it?
return (
<>
{posts.map(post => {
const mapped_post = (
<div className="feed-item">
<div className="feed-item-header">
<div className="feed-item-header-left">
<h2>{post.title}</h2>
</div>
<div className="feed-item-header-right">
<div className="feed-item-header-right-top">
<Link to={`/users/${post.author}`}>
<h3>{post.author}</h3>
</Link>
</div>
<div className="feed-item-header-right-bottom">
<p>Today at {Date.prototype.getHours(new Date(post.date_time))}:{Date.prototype.getMinutes(new Date(post.date_time))}</p>
</div>
</div>
</div>
<div className="feed-item-body">
<p>{post.content}</p>
</div>
</div>
);
return mapped_post;
})}
</>
);