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

350
Vistas
Taking time value and returning a value that will pass a moment().isValid() check

I am running some checks on a value that is passed into a timePicker on my react-native app, and I want to take a time value like 14:29, which is coming in as a string, and turn that into a value that will pass a moment(val).isValid() check.

How can I, for instance, just take today's date, but set the time to be this value of 14:29?

I tried this but it errors out:

let val = '14:29';
this._value = moment(new Date()).startOf(val);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Docs: set, startOf.

const input = '14:29';
const [hour, minute] = input.split(':');

const myMoment = moment()
  .set({ hour, minute })
  .startOf('minute');

console.log(
 { myMoment, isValid: myMoment.isValid() }
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

Note: this will respect the browser timezone meaning different users will get different moments in time, depending on their system's currently set timezone.
To set a particular timezone you might want to use .tz(). Docs: moment timezone.

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