Now you need to do some conversions of your date and hour, you may as well convert them to one of the Java 8 date and time classes — provided you can use Java 8, of course. These classes are much nicer to work with downstream than the old-fashioned Date
class. It’s even more straightforward than the other answers. For example:
LocalDate d = date.toInstant().atZone(ZoneOffset.systemDefault()).toLocalDate();
LocalTime t = startHour.toInstant().atZone(ZoneOffset.systemDefault()).toLocalTime();
LocalDateTime dt = d.atTime(t);
System.out.println(dt);
This prints:
2017-01-28T12:29
Depending on you requirements, it may be that you’ll prefer to stay with a ZonedDateTime
or some other Java 8 type. These classes are quite versatile, so chances are that you can get what you want with few lines of code.
Edit: Some JPA implementations may support the Java 8 date and time classes directly, so you may spare the first two lines and only need the third. See JPA support for Java 8 new date and time API.