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

201
Vistas
How to capture time/date when message was send/button pressed [ Vanilla Javascript ]

Im working on a messaging app and i cant figure out how to capture time when SEND/Enter button was clicked and display it next to the message

Vanilla JS

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So are you trying to display the time the button was clicked, and display it to the sender / recipient in their local time?

If so, you should just be able to use the Date constructor like so:

const date = new Date();

That will give you the UTC time. To convert to local time, you can use the .toLocaleTimeString() method. This would log your local time in US format:

const date = new Date();
console.log(date.toLocaleTimeString('en-US'));

So what you could do is have an event listener on the button, and when the button is clicked, create a new date, and convert to local time.

const button = document.querySelector('button');
const par = document.querySelector('p')

button.addEventListener('click', () => {
    const date = new Date();
  const local = date.toLocaleTimeString('en-US');
  par.innerHTML = local
})
<button>
Click me
</button>

<p>
</p>

JSFiddle: https://jsfiddle.net/f198wvdt/2/

Is this along the lines of what you're looking for?

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