Skip to content

Convert seconds to HH-MM-SS format in JavaScript

In this tutorial, let’s see how to convert seconds to Hours Minutes Seconds (HH-MM-SS) format in JavaScript.

An easy way is to create a date will null value, set seconds to it, read date as string.

Advertisements
let timeInSecs = 5000;
let date= new Date(null);
date.setSeconds(timeInSecs); 
let hhmmsstime = date.toISOString().substr(11, 8);
console.log(hhmmsstime); //01:23:20
See also  Library Fine - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.