- Trending Categories
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
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()); }
- Related Articles
- Duration minus() method in Java
- Duration plus() method in Java
- Duration dividedBy() method in Java
- Duration multipliedBy() method in Java
- Duration toDays() method in Java
- Duration plusMillis() method in Java
- Duration plusSeconds() method in Java
- Duration plusMinutes() method in Java
- Duration plusHours() method in Java
- Duration minusHours() method in Java
- Duration minusDays() method in Java
- Duration toMillis() method in Java
- Duration toNanos() method in Java
- Duration getSeconds() method in Java
- Duration getUnits() method in Java

Advertisements