How to store Date and Time in Meteor for range queries?

后端 未结 1 370
攒了一身酷
攒了一身酷 2021-01-06 18:32

My app needs to create objects that will have a startDate shown in 3 different timezones in browser. The date must also include the exact time. The date should be stored in

相关标签:
1条回答
  • 2021-01-06 19:08

    Everything you need to know about this can be found here. The highlights:

    • Store dates as JavaScript Date objects. They have all the query advantages of integer timestamps, but you don't need to convert them back to Date objects to use them.

    • Range queries work like so: Posts.find({creation_date: {$gte: startDate, $lt: endDate}})

    • You should either have the server do the inserts or use the timesync package to prevent clock skew problems.

    • You can use moment-timezone to format you dates to different timezones. e.g. moment(date).tz("America/New_York").format('l LT')

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