In the java.time framework of Java 8 and later, the Duration class says:
This class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units, such as minutes and hours. In addition, the
DAYSunit can be used and is treated as exactly equal to 24 hours, thus ignoring daylight savings effects.
Yet when I call the get method and pass ChronoUnit.DAYS, an exception is thrown.
LocalTime start = LocalTime.of ( 0 , 0 , 0 ); // First moment of the day.
LocalTime stop = LocalTime.of ( 2 , 0 , 0 ); // 2 AM.
Duration duration = Duration.between ( start , stop );
long days = duration.get ( ChronoUnit.DAYS );
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Days
Am I misunderstanding something, or misusing the classes?