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

108
Vistas
Moment.js works weirdly

I am using Moment to work with time and what I wanted to achieve is to convert local time to UTC time. My local time is GMT+5.

So, here is my code:

moment("12:15", "HH a").utc().format("HH")

What I expect to get is 19 but I get 07. I really need your help. I am using moment.js 2.24.0.

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

0

Use hh to parse the input hours and don't forget the minutes.

console.log(moment('12:15', 'hh:mm').utc().format('HH'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

Since Moment is EOL, you should use Luxon instead.

const { DateTime } = luxon;

console.log(DateTime.fromFormat('12:15', 'hh:mm').toUTC().toFormat('HH'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.0.2/luxon.min.js"></script>

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