Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript format time from number

Number.prototype.toHHMMSS = function () {
    var sec_num = parseInt(this, 10); // don't forget the second param
    var hours   = Math.floor(sec_num / 3600);
    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
    var seconds = sec_num - (hours * 3600) - (minutes * 60);

    if (hours   < 10) {hours   = "0"+hours;}
    if (minutes < 10) {minutes = "0"+minutes;}
    if (seconds < 10) {seconds = "0"+seconds;}
    return hours+':'+minutes+':'+seconds;
}

10800.toHHMMSS() // -> 03:00:00 
Comment

PREVIOUS NEXT
Code Example
Javascript :: show selected image input file from database 
Javascript :: indexof all occurrences javascript 
Javascript :: sumar un mes a una fecha javascript moment 
Javascript :: properly print json in colab 
Javascript :: javascript How to print every number that is divisible by either 3 or 5, but not both 
Javascript :: js code to accept all linkedin requests 
Javascript :: nextjs link image 
Javascript :: color picker in react js 
Javascript :: best react native ui library 
Javascript :: mongooseautoincrement 
Javascript :: how to write a funcat in javascript 
Javascript :: rivets js bind 
Javascript :: javascript js ternary operater 
Javascript :: use axios cancel token in react.js useEffect 
Javascript :: spread operator react 
Javascript :: javascaript 
Javascript :: how to add a class in classlist and remove after 100 ms using jquery 
Javascript :: how to get all scripts on a page javascript 
Javascript :: image downloader extension in nodejs 
Javascript :: use params in Class based component 
Javascript :: javascript display, show properties of object 
Javascript :: delate char betwen index js 
Javascript :: str_limit function filter vuejs 
Javascript :: multer in express.js 
Javascript :: list of states js 
Javascript :: mule 4 json to string json 
Javascript :: react disabled attribute 
Javascript :: file input only allow json 
Javascript :: javascript max characters string function 
Javascript :: react show view based on role permission 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =