So I’m using hibernate and working with an application that manages time. What is the best way to deal with times in a 24 hour clock?
I do not need to worry about TimeZone issues at the beginning of this application but it would be best to ensure that this functionality is built in at the beginning.
I’m using hibernate as well, just as an fyi
Store them as long ts = System.currentTimeMillis(). That format is actually TimeZone-safe as it return time in UTC.
If you only need time part, well, I’m not aware of built-in type in Hib, but writing your own type Time24 is trivial — just implement either org.hibernate.UserType or org.hibernate.CompositeUserType (load=nullSafeGet and store=nullSafeSet methods in them).
See http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-types-custom
But I’d still save absolute time anyway. May help in future.
P.S. That’s all presuming storing Date is out of question for some reason. TimeZone in Date sometimes gets in the way, really. 😉