1

Using a datetime picker and get time in Milli using it get period fro two date pickers.

I have two DatePickers based on user input data is stored in Calendar variable to display in a textview.

LocalDate today = firstdate;
LocalDate secondDate = userpicked date;

Period p = Period.between(today, secondDate);
System.out.println("Date Difference is:" + p.getYears() + " years, " + 
p.getMonths() +
               " months, and " + p.getDays() +
               " days + p.getHours "hours" + p.getMinutes "minutes");

To have for example: Date Difference is: 53 years, 4 months, 29 days, 7 hours, and 30 minutes.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Fathead
  • 11
  • 5
  • Sorry, I didn’t get what you are asking about. And I find no `getHours` method in [`Period`](https://docs.oracle.com/javase/9/docs/api/java/time/Period.html). What sense would it make to give the difference between, say, Jan 17 and Jan 23 this year, in days, *hours and minutes*? A `LocalDate` hasn’t got time of day (I hope you knew that already). – Ole V.V. Jan 21 '19 at 14:35
  • For more attention to your question from those who know, tag it with the language and any library you are using (if you intended Joda-Time, add the jodatime tag instead of the java-time tag that I put there). – Ole V.V. Jan 21 '19 at 14:39

0 Answers0