# Can someone help me come up with a formula for calculating the difference in time? [closed]

So my assignment is to write a program that prompts the user for two different times on the same day (with 0 being midnight, 0700 being 7:00 am and 2200 being 10 pm) and then returns the difference between the two times with the amount of hours and amount of minutes elapsed. For example, if the user inputted 1255 and 1305, the program should return 0 hours and 10 minutes. I'm fine with how to find the number of hours but I cannot come up with a formula for finding the difference in minutes. Here is what I have so far:

    Scanner keyboard1 = new Scanner(System.in);
System.out.print("Train A departs at: ");
int a = keyboard1.nextInt();

Scanner keyboard2 = new Scanner(System.in);
System.out.print("Train B departs at: ");
int b = keyboard2.nextInt();

int difference = Math.abs(a - b);
int hours = difference / 100;
int minutes = (I need help here);

System.out.print("\nDifference: " + hours + " hours and " + minutes + " minutes");

• Note that, outside the context of this programming exercise, you should never attempt to write this kind of code yourself. Date and time manipulations are notoriously difficult because there are a billion and one special cases. For example, daylight saving time adds and subtracts an hour once a year; leap years mean there's an extra day in February. Different countries adopted the Gregorian calendar at different times so, e.g., 1900 was a leap year in Russia but not in England. And leap seconds. Don't even ask about leap seconds. Jun 2, 2015 at 9:29
• Programming exercises are offtopic here. It may be ontopic on Code Review, but check their scope carefully before reposting.
– Raphael
Jun 2, 2015 at 10:33