Home > Back-end >  How to save DateTime to MongoDB with Timezone intact?
How to save DateTime to MongoDB with Timezone intact?

Time:03-29

Hi Im trying to save time and date to Mongo DB but it seems to be changing the date to another format and even when I try in that format it removes the timezone and changes the time

2022-03-30T09:00:46-07:00

becomes

2022-03-30T16:00:46.000 00:00

*My issue is when I send emails to tell clients the time it sends the wrong time completely causing confusion. How can I ensure the timezone get saved in Mongo.

Im using graphql as an api lang if needed.

CodePudding user response:

There was no way to do it. It's best to store timezone separate and convert

CodePudding user response:

sender:

new Date().toISOString()

1

Receiver:

idea: parse iso string to iso date

package: date-fns

method: parseISO(inputISOString)

  • Related