- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to get the duration between two Instant timestamps in Java
Let us first set two Instants with ofEpochSeconds() method using seconds from the epoch of 1970-01- 01T00:00:00Z.
Now get the duration between the above two Instant:
Duration res = Duration.between(one, two);
Example
import java.time.Duration; import java.time.Instant; public class Demo { public static void main(String[] args) { Instant one = Instant.ofEpochSecond(1845836728); Instant two = Instant.ofEpochSecond(1845866935); Duration res = Duration.between(one, two); System.out.println(res); } }
Output
PT8H23M27S
- Related Articles
- How to get the seconds and minutes between two Instant timestamps in Java
- How to get time difference between two timestamps in seconds?
- Java Program to get duration between two time instants
- Get the difference between two timestamps in seconds in MySQL?
- Instant get() method in Java
- MySQL difference between two timestamps in Seconds?
- Duration get() method in Java
- Python program to find difference between two timestamps
- Difference between two timestamps in seconds in MySQL?
- Find the difference between two timestamps in days with MySQL
- Java Program to get Epoch seconds from Instant
- Java Program to get Milli seconds from Instant
- Duration between() method in Java
- Java Program to get the number of hours in this duration
- Java Program to get the number of minutes in this duration

Advertisements