Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Is there a way to get the hours from a Date?

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;
            })}
            </>
        );
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!