How to calculate time difference between a given time and current time in Java?
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Date date = dateFormat.parse("17:40:00"); System.out.println(date); Date date2 = new Date(); date2 = dateFormat.parse(dateFormat.format(date2)); System.out.println(date2); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar calendar2 = calendar.getInstance(); calendar2.setTime(date2); System.out.println((calendar2.getTimeInMillis() - calendar.getTimeInMillis())/60000);