1

The problem I'm having is that I have a n object that includes a Date property. When the object is created or edited, that Date property is sent to the API using an HTTP put or post method, but the value of the date is changed when it's sent out.

What I see before it gets sent out to the API is this:

Sun Nov 03 2019 07:00:00 GMT-0700 (Pacific Standard Time)

I even put it through a conversion function to reset the time to 00:00:00, so it looks like this:

Sun Nov 03 2019 00:00:00 GMT-0700 (Pacific Daylight Time)

But when I look at the network tab in Chrome the value that is sent for that property is this:

2019-11-03T07:00:00.000Z

Every time it's edited, assuming the date isn't changed, the value of that date is incremented by whatever the offset is (7 hours in this case), so after a couple edits the date changed to the next day... I can't figure out how to keep the property a Date, but make the value sent to the API midnight on the date selected.

I'm sure this has been answered so many times, but I've spent hours trying to find the answer to this and all I can come up with is to convert my date to a string, which isn't possible because the DTO has it set as a Date.

Thanks!

Eddie
  • 1,228
  • 3
  • 17
  • 31
  • 2
    2019-11-03T07:00:00.000Z is exactly the same moment in time as Sun Nov 03 2019 00:00:00 GMT-0700 (Pacific Daylight Time), it's just using a different timezone offset (UTC, i.e. 0000, rather than PDT which is -0700). – RobG Oct 31 '19 at 23:23
  • I understand that, but then why does it increment by the offset hours every time it is updated? Shouldn't it remain the same? – Eddie Nov 01 '19 at 15:50
  • Please post code demonstrating the issue. Since the date seems to be being changed from object to string and back, there may be an error in the serialisation or parsing. – RobG Nov 01 '19 at 21:40

0 Answers0