0

I want to get the accurate current date and time for a zone in milliseconds, I found this method.

  .....
    Local Datetime localDateTime2=LocalDateTime.parse(timestamp,DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
   long milliss=localDateTime2.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();

The above works fine but the code displayed requires api 26 and above. Is there a different method that supports lower apis achieving same result. Please help

Yayayaya
  • 216
  • 3
  • 13
  • 1
    I think this has been asked before. The answer is that you can use the same code — `LocalDateTime` and the other classes from java.time — on lower API levels too since java.time has been backported. Get the Android edition of the backport at [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP). And read the longer story at [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Oct 25 '19 at 10:35
  • Also related: [Android date-time manipulation library](https://stackoverflow.com/questions/22525857/android-date-time-manipulation-library). Only when one answer mentions Joda-Time, Joda-Time is now in maintenance mode and not recommended for new code. – Ole V.V. Oct 25 '19 at 10:49
  • And how do I use the same androidthreetenabp to get the time? – Yayayaya Oct 25 '19 at 13:19
  • The code in your question works with ThreeTenABP. Only make sure you import the date and time classes from `org.threeten.bp` with subpackages. – Ole V.V. Oct 25 '19 at 15:03
  • Thank you very much – Yayayaya Oct 25 '19 at 18:49

0 Answers0