Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Which is the best way to store a date in MongoDB without considering the timezone?

I try to explain the problem with an example:

Giuseppe in Italy created an invoce in date "December 15, 2014", when the system store this date, in MongoDB will be stored "2014-12-14T23:00:00.000Z".

John in UK read the invoice and see "December 14, 2014" as the invoice date.

Obviously this information is wrong becouse also Jhon should see "December 15, 2014" as the invoice date, how can I solve this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
233 views
Welcome To Ask or Share your Answers For Others

1 Answer

Whole dates should not be placed in a Date object. Despite the name, Date represents a date and a time. If the value you're working with represents a whole date, rather than a specific time on that date, then you should store the value in another format.

Options are:

  • A string in YYYY-MM-DD or YYYYMMDD format
  • An integer number of whole days since some reference point.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...