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

91
Views
React render Epoch timestamp convert to am pm

I am doing a personal React.js project. I am fetching an API and one of the values it is an Epoch timestamp. I would like to render it as a human readable time like am/pm. The Epoch timestamp is render after a map. Below you can see the code:

{value.map((dog, c) => (
                  <div key={c}>
                    <div><b>Race name:</b> {dog.Venue}</div>
                    <div><b>Start time:</b> {dog.AdvertisedStartTime}</div>

{dog.AdvertisedStartTime} renders a number like: 1641079080000. This numbers are a time in the future, for instance 1:30pm

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can do something like this. First define a helper function to convert Epoch to desired locale and use it inside the map. The function could be

function convertEpoch(value) {
  if (!value) {
    return ''
  }
  const time = new Date(Number(value));
  if (isNaN(time.valueOf())) {
    return '';
  }
  return time.toLocaleString("en-US", { hour: "numeric", minute: "numeric", hour12: true });
}

And use it in your map like

{value.map((dog, c) => (
              <div key={c}>
                <div><b>Race name:</b> {dog.Venue}</div>
                <div><b>Start time:</b> {convertEpoch(dog.AdvertisedStartTime)}</div>
about 4 years ago · Juan Pablo Isaza Report

0

let yourTimestamp = 1641079080000, (any number)
date = new Date(yourTimestamp * 1000),
dateVal = [
  date.getFullYear(),
  date.getMonth()+1,
  date.getDate(),
  date.getHours(),
  date.getMinutes(),
  date.getSeconds(),
];
console.log(dateVal);

Note that : Hours - mins and seconds depend on the time zone of your operating system. in different time zones it can be anything. Hence you can add the time zone offset to the time to create the GMT date:

let myDate = new Date();
date = new Date(timestamp*1000 + myDate.getTimezoneOffset() * 60000)
about 4 years ago · Juan Pablo Isaza Report

0

This is an example how we can get time very easy way.

let today= new Date().toLocaleTimeString(); console.log(today);

so you can try this one:

{value.map((dog, c) => (
          <div key={c}>
            <div><b>Race name:</b> {dog.Venue}</div>
            <div><b>Start time:</b> {convertEpoch(dog.AdvertisedStartTime.toLocaleTimeString();)}</div>
about 4 years ago · Juan Pablo Isaza Report
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!