LegacyConverters { public static LocalTime toLocalTime( Date date ) { Calendar c = Calendar.getInstance(); c.setTime( date ); int hour = c.get( Calendar.HOUR_OF_DAY ); int minute = c.get( Calendar.MINUTE ); int second = c.get( Calendar.SECOND ); int millis = c.get( Calendar.MILLISECOND ); return LocalTime.of( hour, minute, second, millis * milliToNanoConst ); }  static ZonedDateTime toZonedDateTime( Date date ); static ZonedDateTime toZonedDateTime( Date date, ZoneId zoneId ); static LocalDateTime toLocalDateTime( Date date ); static LocalDate toLocalDate( Date date ); static LocalTime toLocalTime( Date date ); static YearMonth toYearMonth( Date date ); static MonthDay toMonthDay( Date date ); static Date toDate( ZonedDateTime dateTime ); static Date toDate( Instant instant ); static Timestamp toTimestamp( ZonedDateTime dateTime ); static Timestamp toTimestamp( Instant instant );  }
@Test public void dateToLocalTimeTest() { long epochMillis = 31415926535L; Date date = new Date( epochMillis ); Calendar c = Calendar.getInstance(); c.setTime( date ); int hour = c.get( Calendar.HOUR_OF_DAY ); int minute = c.get( Calendar.MINUTE ); int second = c.get( Calendar.SECOND ); int millis = c.get( Calendar.MILLISECOND ); LocalTime localTime = toLocalTime( date ); assertEquals( localTime.getHour(), hour ); assertEquals( localTime.getMinute(), minute ); assertEquals( localTime.getSecond(), second ); assertEquals( localTime.getNano(), millis * 1000000 ); }