DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
Date d1 = df.parse("2012-01-24 12:30:00 PM");
Date d2 = df.parse("2012-01-24 02:30:00 PM");
int hoursDifference = (int)((d2.getTime() - d1.getTime()) / 3600000L);
System.out.println("Difference in hours: " + hoursDifference);
No comments:
Post a Comment