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);  

Comments

Post a Comment

Popular posts from this blog

How to get context path in JQuery?

How to extend Liferay 6.2 session timeout by AJAX call?