Found 9150 Articles for Object Oriented Programming

Duration minusMillis() method in Java

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

95 Views

An immutable copy of a duration where some milliseconds are removed from it can be obtained using the minusMillis() method in the Duration class in Java. This method requires a single parameter i.e. the number of milliseconds to be subtracted and it returns the duration with the subtracted milliseconds.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.ofSeconds(1); System.out.println("The duration is: " + d); ... Read More

Duration withNanos() method in Java

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

117 Views

The immutable copy of a duration with the required nanoseconds is obtained using the method withNanos() in the Duration class in Java. This method requires a single parameter i.e. the number of nanoseconds and it returns the duration with the required nanoseconds that were passed as a parameter.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { int nanoseconds = 1000000; Duration duration = Duration.ofHours(10); System.out.println("The duration ... Read More

Duration of() method in Java

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

223 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

130 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

157 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

339 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

172 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

2K+ 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

128 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

180 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

Advertisements