http://blog.progs.be/542/date-to-java-time
Java8 has new date and time classes to “replace” the old not-so-beloved java.util.Date class.
Unfortunately though, converting between the two is somewhat less obvious than you might expect.
Convert java.util.Date to java.time.LocalDateTime
|
The big trick (for all these conversions) is to convert to Instant. This can be converted to LocalDateTime by telling the system which timezone to use. This needs to be the system default locale, otherwise the time will change.
Convert java.util.Date to java.time.LocalDate
|
Convert java.util.Date to java.time.LocalTime
|
Convert java.time.LocalDateTime to java.util.Date
|
Convert java.time.LocalDate to java.util.Date
|
Convert java.time.LocalTime to java.util.Date
|
This one is a little, funny, you need to inject a date to convert the time… Gives you the option of start of epoch or something else.