Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery convert time to 1day 2 minutes 4 seconds

function secondsToDhms(seconds) {
  seconds = Number(seconds);
  var d = Math.floor(seconds / (3600*24));
  var h = Math.floor(seconds % (3600*24) / 3600);
  var m = Math.floor(seconds % 3600 / 60);
  var s = Math.floor(seconds % 60);

  var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
  var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
  var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
  var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
  return dDisplay + hDisplay + mDisplay + sDisplay;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js filter out doubles 
Javascript :: axios fetch 
Javascript :: how to convert a queryset into json string 
Javascript :: set node_env in windows 
Javascript :: javascript throw new error 
Javascript :: string indexing in js 
Javascript :: jquery change button click function 
Javascript :: angular is not defined In AngularJS 
Javascript :: react native modal close when click outside 
Javascript :: jquery get dropdown list selected value 
Javascript :: Capitalize the first letter of string using JavaScript 
Javascript :: javascript fibonacci sequence recursion 
Javascript :: mongodb sort 
Javascript :: how to concatenate strings and variables in javascript 
Javascript :: regex find first instace 
Javascript :: how to empty a filled input in cypress 
Javascript :: how to sort an array of object 
Javascript :: javascript remove query string from url 
Javascript :: socket io emit to socket id 
Javascript :: mongoose put request 
Javascript :: vue mapgetters with parameter 
Javascript :: ngrok live port vue js 
Javascript :: element clicked js 
Javascript :: jquery select option by value 
Javascript :: how to code print in javascript 
Javascript :: node js response header 
Javascript :: export gcp credentials json file 
Javascript :: how to clear node modules folder from your computer 
Javascript :: bin2hex in js 
Javascript :: javascript slice array 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =