Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda