How to Calculate Time Difference in Java?

Given two strings of time, you may want to calculate the difference between them. The following provide a simple solution. import java.text.SimpleDateFormat; import java.util.Date;   public class Main { public static void main(String[] args) throws Exception{ String time1 = "12:00:00"; String time2 = "12:01:00";   SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); Date date1 = format.parse(time1); Date … Read more