Home > Enterprise >  Passing my payload through JSON.parse alters my date object values to not line up
Passing my payload through JSON.parse alters my date object values to not line up

Time:11-27

Prior to using JSON.parse(), my payload contents are as follows:

let payload = {
     "name":"bob",
     "timeDetails":
        [
            {
                "windowName":"Window A",
                "windowTimes":
                    {
                        "startDate":"2021-11-20T20:39:46.785Z",
                        "endDate":"2021-11-20T20:39:54.786Z"
                    }
            }
        ]
    }

So paying particular attention to my dates, when I then proceed to issue the following on the above payload, i.e.:

let job = JSON.parse(payload);
console.log(job);

I am now getting the following startDate and endDate returned which is not the same as my original payload dates, i.e. from my console log:

startDate: Sun Nov 21 2021 16:00:00 GMT 1100 (Australian Eastern Daylight Time) {}
endDate: Sun Nov 21 2021 23:00:00 GMT 1100 (Australian Eastern Daylight Time) {}

I am not so much concerned about the time portion but I would've thought I would've seen the dates as: Sat Nov 20 2021 for both startDate/endDate?

Can someone help with what I am missing as need to ensure that dates are like for like.

CodePudding user response:

Taking date string as UTC Time zone ("2021-11-20T20:39:46.785Z", UTC format). It adds 11 (GMT 1100 (Australian Eastern Daylight Time) hours to UTC time, so adding 11 hours to Nov 20 gets Nov 21 as a result If you want to get the Exact UTC zone we have to convert it to UTC format

  • Related