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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.