Reputation: 539
I would like to find the "interval" between a datetime A, and another latter one. ex.
interval = 4 days 0h 0m 0s
I found this post: How to find difference between two Joda-Time DateTimes in minutes
But I am wondering isn't JodaTime's Interval
supposed to do this ?
If so, how?
Upvotes: 0
Views: 111
Reputation: 44061
You are not looking for an interval (which has anchors on the timeline) but for a duration which is not bound to a specific time on the timeline. Durations based on any time units are called Period
in Joda-Time.
DateTimeFormatter f = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
LocalDateTime ldtA = LocalDateTime.parse("21/09/2015 12:00:00", f);
LocalDateTime ldtB = LocalDateTime.parse("25/09/2015 12:00:00", f);
Period diff = new Period(ldtA, ldtB, PeriodType.dayTime());
System.out.println(PeriodFormat.wordBased(Locale.ENGLISH).print(diff)); // 4 days
Upvotes: 1
Reputation: 252
Its possible but with some additional API usage. Take a look at this page it should help you understand Interval and how to use it appropriately.
Upvotes: 0