
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Duration Between Method in Java
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
import 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()); } }
Output
The duration between the two in seconds is: 43200
Now let us understand the above program.
The duration between the two temporal objects is obtained using the method between() and then this is printed. A code snippet that demonstrates this is as follows −
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()); }
Advertisements