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

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

$
0
0

Using the amazing moment.js library:

function humanizeDuration(input, units ) {   // units is a string with possible values of y, M, w, d, h, m, s, ms  var duration = moment().startOf('day').add(units, input),    format = "";  if(duration.hour() > 0){ format += "H [hours] "; }  if(duration.minute() > 0){ format += "m [minutes] "; }  format += " s [seconds]";  return duration.format(format);}

This allows you to specify any duration be it hours, minutes, seconds, mills, and returns a human readable version.


Viewing all articles
Browse latest Browse all 49


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>