JodatimeUtils { public static Period between(Date start, Date end){ Period p = new Period(start.getTime(), end.getTime()); return p; } private  JodatimeUtils(); static DateTime atStartOfDate(Date date); static DateTime atStartOfDate(Date date, int plusDays); static DateTime atEndOfDate(Date date); static DateTime atEndOfDate(Date date, int plusDays); static DateTime atStartOfMonth(Date date); static DateTime atEndOfMonth(Date date); static String format(Date date, String pattern); static String formatDateTime(Date date); static DateTime parse(String source, String pattern); static DateTime parse(String source); static Interval createInterval(String start, String end); static Interval createInterval(Date start, Date end); static boolean isTimeBetweenInterval(Date theTime, Date start, Date end); static Period between(Date start, Date end); static Period between(LocalDateTime start, LocalDateTime end); static String[] DATE_PATTERNS; static String PATTERN_DATE_TIME; }
@Test public void testBetween(){ Date start = DateUtils.parse("2016-12-06 17:35:30"); Date end = DateUtils.parse("2016-12-06 17:35:33"); Period period = JodatimeUtils.between(start, end); assertThat(period.getSeconds(), equalTo(Seconds.THREE.getSeconds())); assertThat(Seconds.secondsBetween(new LocalDateTime(start), new LocalDateTime(end)), equalTo(Seconds.THREE)); }