Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!