Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

javascript - Store date in MongoDB without considering the timezone

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

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

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...