- 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
Java Program to get minutes between two time instants
At first, create two time instants −
Instant time1 = Instant.now(); Instant time2 = time1.plus(5, ChronoUnit.HOURS).plus(10, ChronoUnit.MINUTES);
Use between() to get the minutes between two time instants −
Duration duration = Duration.ofSeconds(13); Instant i = time1.plus(duration); System.out.println("Minutes between two time instants = "+Duration.between(time1, time2).toMinutes());
Example
import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant time1 = Instant.now(); Instant time2 = time1.plus(5, ChronoUnit.HOURS).plus(10, ChronoUnit.MINUTES); Duration duration = Duration.ofSeconds(13); Instant i = time1.plus(duration); System.out.println("Minutes between two time instants = "+Duration.between(time1, time2).toMinutes()); } }
Output
Minutes between two time instants = 310
Advertisements