开发者

How to make sure that the date gets rendered based on the appropriate timezone

We use the following call to set the Date value and store it in the database.

setCreationDate(new java.util.Date());

Assuming our database server is in PST timezone and user1 (in PST), user2 (in EST), user3 (in GMT). The user screen gets rendered based on timezone properly.

If开发者_开发知识库 I move the database data to a different timezone (say EST), will the behavior remain the same or should I store the date value in GMT itself prior to storage. If so how should I address this?


Date-Times should always be stored as UTC (a.k.a. Zulu Time, GMT). It could be argued that there is one and only one time on this planet and everything else is an interpretation of that to local custom and convenience.

That the Royal Observatory, Greenwich is the place where the real-time matches with the sun is an historical accident, but has proven useful over the last few hundred years (and to be precise, even the sun isn't a great standard, whence UTC, but the general point still holds).

See How to handle calendar TimeZones using Java? for Java details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜