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 = ???

1 Answer 1

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();
1
  • 2
    Thank you. Dates complexity on android is ever puzzling.
    – ror
    Jul 24, 2020 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.