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'
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>