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

147
Views
How to return HH:mm only in date javascript

I'm converting seconds to time using this code,

var seconds = 8274;
new Date(seconds * 1000).toISOString().substr(11, 8)

And it will return like this 02:17:54

I need to return only hours and minutes only like this, 02:17

Please help.

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

0

Fixed it by using this code new Date(seconds * 1000).toISOString().substr(11, 5)

about 4 years ago · Juan Pablo Isaza Report

0

Use the methods getHours() and getMinutes() on the date object like.

const d = new Date();
const h = d.getHours();
const m = d.getMinutes();

const t = h + ":" + m;

If you want it to be prefixed with a leading 0 when hours or minutes are lower than 10 use the length or verify <= 9.

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!