Found 34484 Articles for Programming

Duration of() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

144 Views

The required duration using a particular temporal unit can be calculated with the method of() in the Duration class in Java. This method requires two parameters i.e. the time value and the temporal unit for that value. It returns the time duration with the particular value and temporal unit.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       long timeValue = 2;     Duration d = Duration.of(timeValue, ChronoUnit.HOURS); System.out.println("The duration in minutes is: ... Read More

Duration minusMinutes() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

71 Views

An immutable copy of a duration where some minutes are removed from it can be obtained using the minusMinutes() method in the Duration class in Java. This method requires a single parameter i.e. the number of minutes to be subtracted and it returns the duration with the subtracted minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofMinutes(60); System.out.println("The duration is: " + d); ... Read More

Duration minusSeconds() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

81 Views

An immutable copy of a duration where some seconds are removed from it can be obtained using the minusSeconds() method in the Duration class in Java. This method requires a single parameter i.e. the number of seconds to be subtracted and it returns the duration with the subtracted seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofMinutes(1); System.out.println("The duration is: " + d); ... Read More

Duration ofMillis() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

243 Views

The duration can be obtained in a one millisecond format using the ofMillis() method in the Duration class in Java. This method requires a single parameter i.e. the number of milliseconds and it returns the duration in a one millisecond format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { long milliseconds = 1000; Duration duration = Duration.ofMillis(milliseconds); ... Read More

Duration hashCode() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

111 Views

The hash code value of the duration can be obtained using the hashCode() method in the Duration class in Java. This method requires no parameters and it returns the hash code value of the duration.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofDays(2); System.out.println("The duration is: " + d); System.out.println("The hash code of the duration is: " + d.hashCode()); ... Read More

Duration between() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

1K+ Views

The duration between two temporal objects can be obtained using the method between() in the Duration class in Java. This method requires two parameters i.e. the start duration and the end duration. Also, it returns the duration between these two temporal duration objects.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { Duration d = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println("The duration between the two in seconds is: " + d.getSeconds()); } }OutputThe ... Read More

Duration ofNanos() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

80 Views

The duration can be obtained in a one nano second format using the ofNanos() method in the Duration class in Java. This method requires a single parameter i.e. the number of nano seconds and it returns the duration in a one nano second format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { long nanoseconds = 1000000000; Duration duration = ... Read More

Duration toString() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

115 Views

The string value of the duration can be obtained using the method toString() in the Duration class in Java. This method requires no parameters and it returns the string value of the duration.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofDays(2); System.out.println("The duration is: " + d.toString()); } }OutputThe duration is: PT48HNow let us understand the above program.The string value of the duration is obtained ... Read More

Duration get() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

344 Views

The value of the chronological unit can be obtained using the method get() in the Duration class in Java. This method requires a single parameter i.e. the TemporalUnit for which the value is required. Also, the value of the chronological unit is returned by this method.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; import java.time.temporal.*; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofMinutes(2);       System.out.println("The duration in minutes is: " + d);       long seconds = d.get(ChronoUnit.SECONDS);     System.out.println("The ... Read More

Duration ofSeconds() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

831 Views

The duration can be obtained in a one second format using the ofSeconds() method in the Duration class in Java. This method requires two parameters i.e. the number of seconds and the adjustment required in nanoseconds. Also, it returns the duration in a one second format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       long seconds = 515793;     long adjustment = 100; ... Read More

Advertisements