Mongodb saves one day less - Time Zone Issue

后端 未结 1 753
别那么骄傲
别那么骄傲 2021-01-22 20:32

I post date in the format from angular as MM/DD/YYYY but but when it saves in Mongodb it saves the ISO() format with one day less. I am developing using MEAN stack.

eg

相关标签:
1条回答
  • 2021-01-22 20:46

    The MongoDB saves date time in UTC. So, it changes from IST to UTC before saving. IST offset is +05:30 from UTC. So your date time 10/03/2016 00:00:00 goes back 2016-10-02T18:30:00.000Z, the same date time in UTC.

    You have to set the time back to IST while fetching the data from MongoDb before presenting to the client.

    Btw you should try and save the datetime in ISO format from the beginning.

    More here on the MongoDB doc page for Date

    0 讨论(0)
提交回复
热议问题