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

276
Views
Moment js - format datetime string without considering time zone value

Consider that the string is '2022-02-27T16:45:00-0500'

I need to display it as February 27, 2022, 04:45pm

I tried the following code

moment(dateString).format('MMMM D, YYYY, hh:mma')

But it is returning the value as 'February 28, 2022, 03:15am'. Any idea on how to fix this?

Edit:

I have the following code

moment(dateString).utcOffset(0, true).format('MMMM D, YYYY, hh:mma')

This returns the output as 'February 28, 2022, 03:15am'

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You will need to set utcOffset to -300 which is in minutes for -5 hrs moment().utcOffset(dateString)._offset will give you the offset in minutes

let dateString = '2022-02-27T16:45:00-0500'

let ans = moment(dateString).utcOffset(moment().utcOffset(dateString)._offset).format('MMMM D, YYYY, hh:mma')

console.log(ans)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.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!