Duration from(TemporalUnit) method in Java with Examples Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The from(TemporalUnit) method of Duration Class in java.time package is used to get a duration from the amount passed as the first parameter in the TemporalUnit. The TemporalUnit can be DAYS, HOURS, etc. Syntax: public static Duration from(TemporalUnit amount) Parameters: This method accepts a parameter amount which is amount from which the Duration is to be found, passed as the TemporalUnit. Return Value: This method returns a Duration representing the time of specified amount. Exception: This method throws following unit: ArithmeticException: if numeric overflow occurs. DateTimeException: if unable to convert to a Duration Below examples illustrate the Duration.from() method: Example 1: Java // Java code to illustrate from() method import java.time.Duration; public class GFG { public static void main(String[] args) { // Get the amount Duration duration = Duration.ofDays(5); // Duration using from() method Duration duration1 = Duration.from(duration); System.out.println(duration1.getSeconds()); } } Output: 432000 Example 2: Java // Java code to illustrate from() method import java.time.Duration; public class GFG { public static void main(String[] args) { // Get the amount Duration duration = Duration.ofHours(5); // Duration using from() method Duration duration1 = Duration.from(duration); System.out.println(duration1.getSeconds()); } } Output: 18000 Reference: Oracle Doc Comment More infoAdvertise with us Next Article Duration plus(long, TemporalUnit) method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-time package Java-Duration Practice Tags : Java Similar Reads Duration get(TemporalUnit) method in Java with Examples The get(TemporalUnit) method of Duration Class in java.time package is used to get the value of the unit passed as the parameter. Only units SECONDS and NANOS ate supported by this method and the rest result in exception. Syntax: public long get(TemporalUnit unit) Parameters: This method accepts a p 2 min read Duration get(TemporalUnit) method in Java with Examples The get(TemporalUnit) method of Duration Class in java.time package is used to get the value of the unit passed as the parameter. Only units SECONDS and NANOS ate supported by this method and the rest result in exception. Syntax: public long get(TemporalUnit unit) Parameters: This method accepts a p 2 min read Duration of(long, TemporalUnit) method in Java with Examples The of(long, TemporalUnit) method of Duration Class in java.time package is used to get a duration of the amount passed as the first parameter in the TemporalUnit passed as the second parameter. The TemporalUnit can be DAYS, HOURS, etc. Syntax: public static Duration of(long amount, TemporalUnit uni 2 min read Duration plus(long, TemporalUnit) method in Java with Examples The plus(long, TemporalUnit) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified duration added, passed as the parameter. The duration to be added is decided by converting the amountToAdd in the unit passed as the parameters. Syntax: pub 2 min read Duration plus(long, TemporalUnit) method in Java with Examples The plus(long, TemporalUnit) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified duration added, passed as the parameter. The duration to be added is decided by converting the amountToAdd in the unit passed as the parameters. Syntax: pub 2 min read Duration minus(long, TemporalUnit) method in Java with Examples The minus(long, TemporalUnit) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified duration subtracted, passed as the parameter. The duration to be subtracted is decided by converting the amountToAdd in the unit passed as the parameters. 2 min read Like