Calculating hours with Java 8

2

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?

    
asked by anonymous 26.11.2014 / 00:21

1 answer

1

It seems to me that the three forms are correct and are equivalent.

However, it seems to me that all three will fail if there are changes related to daylight saving time or change of time zone.

    
26.11.2014 / 00:23