I am trying to calculate the difference between two LocalDateTime.
The output needs to be of the format y years m months d days h hours m minutes
Here is a very simple answer to your question. It works.
import java.time.*;
import java.util.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
public class MyClass {
public static void main(String args[]) {
DateTimeFormatter T = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
Scanner h = new Scanner(System.in);
System.out.print("Enter date of birth[dd/mm/yyyy hh:mm]: ");
String b = h.nextLine();
LocalDateTime bd = LocalDateTime.parse(b,T);
LocalDateTime cd = LocalDateTime.now();
long minutes = ChronoUnit.MINUTES.between(bd, cd);
long hours = ChronoUnit.HOURS.between(bd, cd);
System.out.print("Age is: "+hours+ " hours, or " +minutes+ " minutes old");
}
}