Found 9326 Articles for Object Oriented Programming

Duration ofMillis() method in Java

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

241 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

109 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

79 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

113 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

333 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

817 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

Duration negated() method in Java

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

86 Views

An immutable copy of a duration where the duration is negated can be obtained using the negated() method in the Duration class in Java. This method requires no parameters and it returns the negated duration. Also, if a numeric overflow occurs the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofHours(1); System.out.println("The duration is: " + d); System.out.println("A copy with ... Read More

Duration toMinutes() method in Java

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

141 Views

The value of a duration in the form of a number of minutes can be obtained using the method toMinutes() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More

Duration toHours() method in Java

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

122 Views

The value of a duration in the form of a number of hours can be obtained using the method toHours() in the Duration class in Java. This method does not require any parameters and it returns the duration in the form of a number of hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class GFG { public static void main(String[] args) { Duration d = Duration.ofDays(1); System.out.println("The duration is: " + d); System.out.println("Number of ... Read More

Advertisements