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

301
Vistas
jonthornton timepicker : How to get hours and minues

I'm using the jonthornton/jquery-timepicker and could not find the hours and minutes selected.
All I could find was a string output of the form '10:30pm'.
Can the hours and minutes be accessed directly from the control?
I imagined you would be able to do this but could not find it.
The best I've been able to do is what follows, anyone got anything better?

$('#StartTime').on('change', function (timeControl) {
    var hoursString;
    if (timeControl.target.value.indexOf("am") >= 0) {
        hoursString = timeControl.target.value.replace("am", ":00 AM");
    }
    else {
        hoursString = timeControl.target.value.replace("pm", ":00 PM");
    }
    var oneDate = new Date(Date.parse("2000-01-01 " + hoursString));
    var minutes = oneDate.getMinutes();
    var hours = oneDate.getHours();

    console.log("Hours : " + hours + " | Minutes : " + minutes);
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The long-standing answer would be Moment.js but it is now considered a legacy project in maintenance mode and not recommended for new projects. There are recommendations on their website for replacements, but bringing in a new dependency for this may be overkill.

The value coming in seems to follow a format which we can rely on to make parsing easy.

Format: H:MMxx

Key:

  • H = hour, 1-2 characters
  • MM = minutes, always 2 characters
  • xx = am or pm, always 2 characters
var timeArray = timeControl.split(':');
var meridiem = timeArray[1].substring(2, 4);

var hours = parseInt(timeArray[0]) + (meridiem === 'pm' ? 12 : 0);
var minutes = parseInt(timeArray[1].substring(0, 2));
var seconds = 0;

// Local time zone, read more: https://stackoverflow.com/a/29297375/5988852
var date = new Date(); 
date.setHours(hours, minutes, seconds);

// If you want UTC instead
utc =  Date.UTC(
  date.getUTCFullYear(), 
  date.getUTCMonth(), 
  date.getUTCDate(), 
  hours, 
  minutes, 
  seconds
);
var date = new Date(utc);
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