我想找到" interval"在日期时间A和另一个日期时间之间。 离。
间隔= 4天0h 0m 0s
我发现这篇文章: How to find difference between two Joda-Time DateTimes in minutes
但我想知道JodaTime的Interval
应该这样做吗?
如果是这样,怎么样?
答案 0 :(得分:1)
您不是在寻找一个间隔(在时间轴上有锚点),而是在一段时间内没有被绑定到时间线上的特定时间。基于任何时间单位的持续时间在Joda-Time中称为Period
。
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
答案 1 :(得分:0)
它可能但有一些额外的API使用。看一下这个页面,它可以帮助您了解Interval以及如何正确使用它。