I am seeing a weird behaviour with momentjs parseZone function when using it to parse a date-time string containing UTC offset +00:00. The issue is mentioned as comments in the code snippet below:
var a1 = 'Jan 24, 2024 12:43 +00:00';
var a = moment.parseZone(a1, 'MMM DD, YYYY hh:mm A Z');
console.log(">>>> a: " + a.format());
// outputs unexpected 2024-01-23T18:30:00Z
var b1 = 'Jan 24, 2024 12:43';
var b = moment.parseZone(b1, 'MMM DD, YYYY hh:mm A');
console.log(">>>> b: " + b.format());
// outputs expected 2024-01-24T12:43:00Z
var c1 = "Jan 24, 2024 10:54 +00:00";
var c = moment.parseZone(c1, 'MMM DD, YYYY hh:mm Z')
console.log(">>>> c: " + c.format());
// outputs expected 2024-01-24T10:54:00Z
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js"></script>
Can anybody please explain why a holds unexpected result but b and c expected result?
Thanks.
=========== Update
Based on the comments rectifying the following parts in the code-snippet above resolves the issue
var a1 = 'Jan 24, 2024 12:43 PM +00:00'; // added PM
var a = moment.parseZone(a1, 'MMM DD, YYYY hh:mm A Z'); // removed one space before `hh`
var b = moment.parseZone(b1, 'MMM DD, YYYY hh:mm'); // removed one space before `hh`
var c = moment.parseZone(c1, 'MMM DD, YYYY hh:mm Z') // removed one space before `hh`