Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

702
Views
Javascript - Converting total Minutes into Days, Hours and Minutes without using Math.Floor

I am having total Minutes and i want to convert that total minutes into number of Days, Hours and Minutes format.

var duration = getControlValue('incident','incident_open_duration');
var formattedDuration = duration/24/60 + ":" + duration/60%24 + ':' + duration%60);
alert(formattedDuration);

If the total minutes is 8289.66 , the above line of code returns 5.756708333333333:18.161:9.659999999999854

I don't need decimals, i want to eliminate and round off them so i used Math.floor(time/24/60) + ":" + Math.floor(time/60%24) + ':' + Math.floor(time%60) but unfortunately my tool is not supporting Math.floor function

Do we have any other way of achieving this ?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

You can use double Bitwise_NOT

var duration = 8289.66;
var cleanDuration = ~~(duration / 24 / 60) + ":" + ~~(duration / 60 % 24) + ':' + ~~(duration % 60);
console.log(cleanDuration);
//Suggested by @STh format if you need a format like HH:mm:ss
var formattedDuration = String(~~(duration / 24 / 60)).padStart(2, '0') + ":" + String(~~(duration / 60 % 24)).padStart(2, '0') + ':' + String(~~(duration % 60)).padStart(2, '0')

console.log(formattedDuration);

The snippet above adds leading zeros if the hours / minutes / seconds are only one digit via the padStart method.

Another alternative is Left_shift, Right_shift or Unsigned right shift with 0

var duration = 8289.66;
var formattedDuration = ((duration / 24 / 60) << 0) + ":" + ((duration / 60 % 24) << 0) + ':' + ((duration % 60) << 0);
console.log("Left Shift Example" , formattedDuration);

var formattedDuration = ((duration / 24 / 60) >> 0) + ":" + ((duration / 60 % 24) >> 0) + ':' + ((duration % 60) >> 0);
console.log("Rigth Shift Example" , formattedDuration);

var formattedDuration = ((duration / 24 / 60) >>> 0) + ":" + ((duration / 60 % 24) >>> 0) + ':' + ((duration % 60) >>> 0);
console.log("Unsigned right shift Example" , formattedDuration);

Or Bitwise_OR with 0

var duration = 8289.66;
var formattedDuration = ((duration / 24 / 60)|0) + ":" + ((duration / 60 % 24)|0) + ':' + ((duration % 60)|0)

console.log(formattedDuration);

about 4 years ago · Santiago Gelvez Report

0

There are the GET Dates method, with which you can extract the components from a date. If you only have the duration, you can, e.g., use the new Date(duration_in_ms) constructor.

So, to fit your use case, the code is:

const x = new Date(duration * 60 * 1000).getXXX()

where getXXX is one of the GET Dates-methods.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!