I was doing some testing with java 8, and was trying to figure out the difference between hours of two dates. I did it three ways, though, I do not know which one would be the right one and would like your help.
LocalDateTime t1 = LocalDateTime.of(2014, Month.NOVEMBER, 25, 8, 23);
LocalDateTime t2 = LocalDateTime.of(2014, Month.NOVEMBER, 25, 10, 23);
long horas = ChronoUnit.HOURS.between(t1, t2);
System.out.println(horas);
long horas2 = t1.until(t2, ChronoUnit.HOURS);
System.out.println(horas2);
long horas3 = Duration.between(t1, t2).toHours();
System.out.println(horas3);
As far as documentation goes, horas2
and horas3
are equivalent, but I was in doubt about the first mode. Is that correct?