Search code examples
javascriptmomentjsmoment-timezone

Incorrect date conversion of JSON dates using moment, OffSet value is ignored


I am making an api call and getting the below response.

{
    "Country": "U.S.A.",
    "FaceValueCcy": "",
    "IsApproved": true,
    "MDate": "/Date(1742130000000+1100)/",
    "MtmInUsd": 0,
}

When I am trying to convert the MDate into 'DD-MMM-YYYY' format. I am expecting the result as '17-Mar-2025' but it is giving me the output as '16-Mar-2025'. This is the code I am using to convert the date.

moment('/Date(1742130000000+1100)/').utc().format('DD-MMM-YYYY')

When I query the value '1742130000000' in epochconvertor, it gives me 16-Mar-2025. why moment is ignoring +1100? Is there any alternate way to resolve this issue?


Solution

  • It should be:

    moment.parseZone('/Date(1742130000000+1100)/').format('DD-MMM-YYYY')