Quantcast
Channel: JavaScript seconds to time string with format hh:mm:ss - Stack Overflow
Browsing all 49 articles
Browse latest View live

Answer by Safwat Fathi for JavaScript seconds to time string with format...

I think this function will do the trick:const isoToDate = ( iso: string, options?: Intl.DateTimeFormatOptions) => { const date = new Date(iso) const time = date.toLocaleTimeString( [], options || {...

View Article


Answer by Chris for JavaScript seconds to time string with format hh:mm:ss

Here's a variation of @meiyang's excellent solution that I ended up using: function duration(seconds) { return [ format(seconds / 60 / 60), format(seconds / 60 % 60), format(seconds % 60) ].join(':');...

View Article


Answer by RyadPasha for JavaScript seconds to time string with format hh:mm:ss

function secToTime(seconds, separator) { return [ parseInt(seconds / 60 / 60), parseInt(seconds / 60 % 60), parseInt(seconds % 60) ].join(separator ? separator : ':') .replace(/\b(\d)\b/g,...

View Article

Answer by Mr. Polywhirl for JavaScript seconds to time string with format...

Here is an example of using Date.prototype.toLocaleTimeString(). I chose GB as the language, because the US shows a 24 instead of a 00 for the initial hour. Furthermore, I chose Etc/UTC as the time...

View Article

Answer by Petr Újezdský for JavaScript seconds to time string with format...

The most general answer to this isfunction hms(seconds) { return [3600, 60] .reduceRight( (p, b) => r => [Math.floor(r / b)].concat(p(r % b)), r => [r] )(seconds) .map(a =>...

View Article


Answer by Arjun Kava for JavaScript seconds to time string with format hh:mm:ss

Easiest way to do it.new Date(sec * 1000).toISOString().substr(11, 8)

View Article

Answer by Matt Kenefick for JavaScript seconds to time string with format...

This is one I wrote recently for MM:SS. It's not exact to the question, but it's a different one-liner format.const time = 60 * 2 + 35; // 2 minutes, 35 secondsconst str = (~~(time / 60)...

View Article

Answer by Big Sam for JavaScript seconds to time string with format hh:mm:ss

Here is a fairly simple solution that rounds to the nearest second!var returnElapsedTime = function(epoch) { //We are assuming that the epoch is in seconds var hours = epoch / 3600, minutes = (hours %...

View Article


Answer by Max Yari for JavaScript seconds to time string with format hh:mm:ss

I saw that everybody's posting their takes on the problem despite the fact that few top answers already include all the necessary info to tailor for the specific use case.And since I want to be hip as...

View Article


Answer by DataGreed for JavaScript seconds to time string with format hh:mm:ss

Here's a one-liner updated for 2019://your datevar someDate = new Date("Wed Jun 26 2019 09:38:02 GMT+0100") var result =...

View Article

Answer by Godwin Vinny Carole for JavaScript seconds to time string with...

Here is an es6 Version of it:export const parseTime = (time) => { // send time in seconds// eslint-disable-next-line let hours = parseInt(time / 60 / 60), mins = Math.abs(parseInt(time / 60) -...

View Article

Answer by Israel for JavaScript seconds to time string with format hh:mm:ss

secToHHMM(number: number) { debugger; let hours = Math.floor(number / 3600); let minutes = Math.floor((number - (hours * 3600)) / 60); let seconds = number - (hours * 3600) - (minutes * 60); let H, M,...

View Article

Answer by artnikpro for JavaScript seconds to time string with format hh:mm:ss

/** * Formats seconds (number) to H:i:s format. * 00:12:00 * * When "short" option is set to true, will return: * 0:50 * 2:00 * 12:00 * 1:00:24 * 10:00:00 */export default function formatTimeHIS...

View Article


Answer by JukkaP for JavaScript seconds to time string with format hh:mm:ss

const secondsToTime = (seconds, locale) => { const date = new Date(0); date.setHours(0, 0, seconds, 0); return date.toLocaleTimeString(locale);}console.log(secondsToTime(3610, "en"));where the...

View Article

Answer by Boris Yakubchik for JavaScript seconds to time string with format...

There's a new method for strings on the block: padStartconst str = '5';str.padStart(2, '0'); // 05Here is a sample use case: YouTube durations in 4 lines of JavaScript

View Article


Answer by Rakesh for JavaScript seconds to time string with format hh:mm:ss

function secondsToTime(secs){ var hours = Math.floor(secs / (60 * 60)); var divisor_for_minutes = secs % (60 * 60); var minutes = Math.floor(divisor_for_minutes / 60); var divisor_for_seconds =...

View Article

Answer by Oleksiy Kachynskyy for JavaScript seconds to time string with...

You can use Momement.js with moment-duration-format plugin:var seconds = 3820;var duration = moment.duration(seconds, 'seconds');var formatted = duration.format("hh:mm:ss");console.log(formatted); //...

View Article


Answer by meiyang for JavaScript seconds to time string with format hh:mm:ss

function formatTime(seconds) { return [ parseInt(seconds / 60 / 60), parseInt(seconds / 60 % 60), parseInt(seconds % 60) ] .join(":") .replace(/\b(\d)\b/g, "0$1")}

View Article

Answer by John Slegers for JavaScript seconds to time string with format...

You can use the following function to convert time (in seconds) to HH:MM:SS format :var convertTime = function (input, separator) { var pad = function(input) {return input < 10 ? "0" + input :...

View Article

Answer by phpFreak for JavaScript seconds to time string with format hh:mm:ss

//secondsToTime(); var t = wachttijd_sec; // your seconds var hour = Math.floor(t/3600); if(hour < 10){ hour = '0'+hour; } var time = hour+':'+('0'+Math.floor(t/60)%60).slice(-2)+':'+('0'+ t %...

View Article
Browsing all 49 articles
Browse latest View live


Latest Images