Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

707
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda