I'm not familiar with the DateTime class, so I can't help you there. How I'd do it though would just to call getTime() on the two Date instances. The difference of the those two values would be the time difference in milliseconds and it would just take some simple arithmetic to convert that to hours.
Winston is correct. You should be doing some validation before you call this method. I mean, what if someone enters the date as "eight thirty-two"? You can't allow that, can you? Therefore, the users have to be told which format the date should be entered, and you can therefore tell them that they must enter it in 24 hour format - there isn't anything unreasonable with that.
Campbell Ritchie wrote:Where does the DateTime class come from? It does not appear to be in the standard Java8 API.
Use the new Java8 time classes as described in the Java™ Tutorials. Stop using Date Calendar etc.
I was guessing it's JodaTime. But you're right that java.time should be used. One advantage is that a single (public/private) static final DateTimeFormatter can be used, since (unlike DateFormat and SimpleDateFormat), it's thread-safe (immutable even).