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

282
Vistas
I want to get the number of days and hours and minutes from a string

You would input like 1d5h40m and it would output 1 day, 5 hours and 40 minutes - Any ways to do that?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Split the input string with non digits and extract what you need from that splitted string. This will only work if input is in the exact pattern you mentioned.

let str = '1d5h40m';
let time = str.split(/\D/);
console.log(time[0] + 'day', time[1] + 'hour', time[2] + 'minute');
about 4 years ago · Juan Pablo Isaza Denunciar

0

How about this? Although you would have to do more work to figure out the plurality of day(s), hour(s) and minute(s).

const duration = '1d5h40m';
var formatted = duration
  .replace('d', ' day, ')
  .replace('h', ' hours and ')
  .replace('m', ' minutes ');
console.log(formatted);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Its lengthy but working

var time="1d5h40m";
const day = time.split("d")[0];
time = time.replace(day+"d", "");
const hours = time.split("h")[0];
time = time.replace(hours+"h", "");
const minutes = time.split("m")[0];
console.log(day+" day, "+hours+" hours and,"+minutes+" minutes");
about 4 years ago · Juan Pablo Isaza 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