13

NOTE: This is answered already excellently in the JDK world here, but the accepted answer doesn't apply to the Android port of JSR-310 which doesn't have that extended API for Date.

So, what is the best way to convert a java.util.Date to org.threeten.bp.LocalDate?

Date input = new Date();
LocalDate date = ???
Community
  • 1
  • 1
Alex Florescu
  • 5,096
  • 1
  • 28
  • 49

1 Answers1

23

This should do it (inspired by https://stackoverflow.com/a/27378709/286419).

Date dateJavaFormat = new Date();
LocalDate dateThreeTenFormat = Instant.ofEpochMilli(dateJavaFormat.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
Community
  • 1
  • 1
Alex Florescu
  • 5,096
  • 1
  • 28
  • 49