I have the following scenario:
- Swing control that returns a
Calendarobject - Intermediate
DateTimeobject that I use to do heavy date/time manipulation (joda) - Database connection (
OraclePreparedStatement) that only takes ajava.sql.Dateobject
My problem is that the Calendar and DateTime objects are properly displaying the date in GMT (which I want), but when I convert to java.sql.Date in order to send to the database, the date is converted to the local time zone.
For example:
CalendarandDateTimeare 2012-08-13T23:59:59.000Z (correct GMT)- Resulting
java.sql.Dateis 2012-08-14 (incorrect local UTC+2 date)
Below is the code I'm using to do the conversion.
DateTime dateGmt = new DateTime(calendarGmt.getTimeInMillis(), DateTimeZone.UTC);
java.sql.Date sqlDate = new java.sql.Date(dateGmt.getMillis());
I don't know how to create a java.sql.Date object while retaining the correct time zone. It's also entirely possible that I'm doing an incorrect conversion.