ChronoUnit getDuration() method in Java with Examples
Last Updated :
29 Jan, 2020
The getDuration() method of ChronoUnit enum is used to return the estimated duration of this ChronoUnit in the ISO calendar system.Days vary due to daylight saving time, while months have different lengths.
Syntax:
public Duration getDuration()
Parameters: This method accepts nothing.
Return value: This method returns the estimated duration of this unit, not null.
Below programs illustrate the ChronoUnit.getDuration() method:
Program 1:
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class GFG {
public static void main(String[] args)
{
ChronoUnit chronoUnit
= ChronoUnit.valueOf( "NANOS" );
Duration getDurationAttribute
= chronoUnit.getDuration();
System.out.println(
"Duration Estimated :"
+ getDurationAttribute);
}
}
|
Output:
Duration Estimated :PT0.000000001S
Program 2:
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class GFG {
public static void main(String[] args)
{
ChronoUnit chronoUnit
= ChronoUnit.valueOf( "DAYS" );
Duration getDurationAttribute
= chronoUnit.getDuration();
System.out.println(
"Duration Estimated :"
+ getDurationAttribute);
}
}
|
Output:
Duration Estimated :PT24H
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoUnit.html#getDuration()
Share your thoughts in the comments
Please Login to comment...