java - Duration does not support DAYS contrary to class documentation -
in java.time framework of java 8 , later, duration
class says:
this class models quantity or amount of time in terms of seconds , nanoseconds. can accessed using other duration-based units, such minutes , hours. in addition,
days
unit can used , treated equal 24 hours, ignoring daylight savings effects.
yet when call get
method , pass chronounit.days
, exception thrown.
localtime start = localtime.of ( 0 , 0 , 0 ); // first moment of 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 misunderstanding something, or misusing classes?
documentation get
on duration class.
gets value of requested unit. returns value each of 2 supported units, seconds , nanos. other units throw exception.
however, duration
class has method called todays
:
gets number of days in duration. returns total number of days in duration dividing number of seconds 86400. based on standard definition of day 24 hours.
Comments
Post a Comment