- 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
How to get the seconds and minutes between two Instant timestamps in Java
The following are the two Instant timestamps:
Instant one = Instant.ofEpochSecond(1355836728); Instant two = Instant.ofEpochSecond(1355866935);
Get the Duration between both the Instant:
Duration res = Duration.between(one, two);
Now, get the seconds between the two timestamps:
long seconds = res.getSeconds();
Now, get the minutes between the two timestamps:
long minutes = res.abs().toMinutes();
Example
import java.time.Duration; import java.time.Instant; public class Demo { public static void main(String[] args) { Instant one = Instant.ofEpochSecond(1355836728); Instant two = Instant.ofEpochSecond(1355866935); Duration res = Duration.between(one, two); System.out.println(res); long seconds = res.getSeconds(); System.out.println("Seconds between Durations = "+seconds); long minutes = res.abs().toMinutes(); System.out.println("Minutes between Durations = "+minutes); } }
Output
PT8H23M27S Seconds between Durations = 30207 Minutes between Durations = 503
- Related Articles
- How to get the duration between two Instant timestamps in Java
- How to get time difference between two timestamps in seconds?
- Get the difference between two timestamps in seconds in MySQL?
- MySQL difference between two timestamps in Seconds?
- Difference between two timestamps in seconds in MySQL?
- Java Program to get Epoch seconds from Instant
- Java Program to get Milli seconds from Instant
- Java Program to get minutes between two time instants
- Java Program to minus seconds and nanoseconds from Instant
- How to convert JavaScript seconds to minutes and seconds?
- Java Program to get the difference between two time zones by seconds
- How to get the number of seconds between two Dates in JavaScript?
- How to Convert Time Difference between Two Times to Number (Hours/Minutes/Seconds) in Excel?
- How to get hour, minutes and seconds in android using offset time API class?
- C# Program to get the difference between two dates in seconds

Advertisements