Java tutorial
import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; public class Main { public static void main(String[] args) throws java.lang.Exception { String[] StartTimes = { "10:00", "7:00" }; String[] EndTimes = { "12:00", "14:56" }; for (int i = 0; i < StartTimes.length; i++) { if (StartTimes != null && StartTimes.length > 0 && EndTimes != null && EndTimes.length > 0) { SimpleDateFormat format = new SimpleDateFormat("HH:mm"); Date date1 = format.parse(StartTimes[i]); Date date2 = format.parse(EndTimes[i]); long millis = date2.getTime() - date1.getTime(); String hourminute = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis))); System.out.println(hourminute); } } } }