I've got a MySQL table with a date() and time() columns like
CREATE TABLE `vol` (
`ID` bigint(20) unsigned NOT NULL,
`DEPART_DATE_VOL` date NOT NULL,
`DEPART_HEURE_VOL` time NOT NULL,
`ARRIVEE_DATE_VOL` date NOT NULL,
`ARRIVEE_HEURE_VOL` time NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I need to query rows using the date() in the WHERE clause so I won't have a datetime() or timestamp (also, I can't modify the DB)
When getting the info in my DAO, I concat the date and time columns to parse a Java Date like:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
addon.setDateDepart(sdf.parse(rs.getString(DEPART_DATE_VOL) + " " + rs.getString(DEPART_HEURE_VOL)));
addon.setDateArrivee(sdf.parse(rs.getString(ARRIVEE_DATE_VOL) + " " + rs.getString(ARRIVEE_HEURE_VOL)));
For a row with departure date:
- 2018-02-26 10:50:00 the resulting Java date is correct
But for the arrival date:
- 2018-02-26 12:20:00 the resulting Java date is set to 2018-02-26T00:20:00
TMP Solution
For now, I'll stick to
addon.setDateDepart(new LocalDateTime(rs.getString(DEPART_DATE_VOL) + "T" + rs.getString(DEPART_HEURE_VOL)).toDate());
addon.setDateArrivee(new LocalDateTime(rs.getString(ARRIVEE_DATE_VOL) + "T" + rs.getString(ARRIVEE_HEURE_VOL)).toDate());
which seems to work, altough I'm not sure if I will run into timezone problems...