I am developing a race timing system, and for several instances, I need to retrieve a time object from H2DB. Like its bretheren (or sisteren), the time data type is relative to
java.util.Date
is always the UTC time. So, depending of your locale, there will be probably an offset.
I have heard of Joda Time
as a better Java API for dealing with times.
Anyway, the problem comes from mixing dates treated by java.util.Date
and others directly passed as part of the SQL.
As long as you keep using java.util/sql.Date
for everything (and you don't peak inside the DB)(and you don't change the locale) the results will be coherent. The trouble will begin when your SQL tries to pass the values directly as text. So either use Date
everywhere or, as trashgod says, everytime you use a Date
you take care of setting the Locale to "GMT" (so the internal representation and the output of the Date are the same). Note that this does include Date
returned from the DB