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

198
Views
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 answers
Answer question

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 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!