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

120
Vistas
Can't format moment object to date and time

I'm using a react component for Date picking which returns a moment object. Also, I'm using my custom component to select time and saving the value like this for example 3:30 pm .

What I want to do is make this one moment object that I can later user and format however I want.

This is my current implementation but it's not working:

formatting the time is always returning AM

const time = moment(pickupTime.formattedTime, ['hh:mm a'])
        .locale('en')
        .format('hh:mm A');

const dateTime =
        startDay.locale('en').format('MMM Do YY') + // This is the Date which is a moment object
        ' ' +
        time;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because string + string = string, you cannot get an object by concatenating strings.

What you need is to convert a string to a moment object:

moment('24/12/2019 09:15:00', "DD MM YYYY hh:mm:ss");

Result:

Moment {_isAMomentObject: true, _i: '24/12/2019 09:15:00', _f: 'DD MM YYYY hh:mm:ss', _isUTC: false, _pf: {…}, …}

Check out https://momentjs.com/docs/#/parsing/string-format/

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