Java Calculate Number of Minutes Between two LocalTime
Tags: Java LocalTime ChronoUnit Java 8
In this Java core tutorial we learn how to calculate the number of minutes between two LocalTime objects using the java.time.temporal.ChronoUnit class in Java programming language.
How to get the number of minutes between two LocalTime
In Java, we can use the ChronoUnit.MINUTES.between() method to calculate the number of minutes between two LocalTime values as the following example Java code.
MinutesBetweenLocalTimeExample.java
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
public class MinutesBetweenLocalTimeExample {
public static void main(String... args) {
LocalTime startTime = LocalTime.of(10, 20, 30);
LocalTime endTime = LocalTime.of(12, 10, 40);
// Calculate Number of Minutes Between two LocalTime
long numberOfMinutes = ChronoUnit.MINUTES.between(startTime, endTime);
System.out.println(String.format("Number of minutes between %s and %s is %d", startTime, endTime, numberOfMinutes));
}
}
Number of minutes between 10:20:30 and 12:10:40 is 110
Happy Coding 😊
Related Articles
Java Calculate Number of Hours Between two LocalTime
Java Calculate Number of Seconds Between two LocalTime