I would like to convert a data in horas
format in minutes using JQuery
Data to convert
var hora='3:19:00';
result
var nuevoDato= '199';
I would like to convert a data in horas
format in minutes using JQuery
Data to convert
var hora='3:19:00';
result
var nuevoDato= '199';
A different way of doing it would be to use JavaScript dates, although is not ideal because it has quite a few limitations. For example: the format of the text must be perfect (following the pattern hh:mm:ss
) and the hours must be valid (you can not have more than 23 hours or 59 minutes).
The idea would be to use an object of type Date
to pause and work with time:
// hora a convertir
var t = "03:19:00";
// creamos una fecha genérica con tu tiempo
var d = new Date("0001-01-01T"+t);
// calculamos los minutos a partir de las horas y minutos de la fecha creada
var minutos = d.getHours() * 60 + d.getMinutes();
console.log(minutos);
You can separate the parts with split and do the calculation from there:
//dato a convertir
var hora='3:19:00';
// Dividir en partes
var parts = hora.split(':');
// Calcular minutos (horas * 60 + minutos)
var total = parseInt(parts[0]) * 60 + parseInt(parts[1]);
console.log(total);
with the java script split option you separate the data by minutes, seconds and hours and perform the conversion
<script type="text/javascript">
var pizza = "02:34:56";
var porciones = pizza.split(':');
document.write(porciones[0]);
document.write(porciones[1]);
document.write(porciones[2]);
</script>