开发者

Working with timezones in Rails and Java

I have a system that will store user timezone information. As the title suggests, I'll be working with it in both Rails and Java.

What would be the least painful way to persist timezone information that will be usable开发者_运维技巧 in both Rails and Java?


Simply store the zoneinfo (aka Olson) time zone ID (e.g. "Europe/London") - both Java and Ruby can use that, as can Joda Time, which is a far superior Java library to the built-in API.

Storing the date/time data itself is a separate matter of course, and will depend on which database you're working with. You need to decide whether you're working with instants in time or local date/time values, primarily. Assuming you're working with instants, one option is to simply store the number of milliseconds (or seconds) since the Unix epoch (midnight on the 1st January 1970 UTC). Of course if the database has a date/time type which doesn't get in the way (in terms of performing its own time zone conversions) then that would be a good choice too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜