- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
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
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
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
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
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
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
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
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
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
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