I have two Strings of the format "hh:mm:ss".I want to obtain only the hour part of both strings and find the difference between them.How should i do it.I tried Dateformat and parse function but when i subtract, it tells bad operand types. Code:
String ta="";
String tb="";
int diff;
Scanner s=new Scanner(System.in);
ta=s.nextLine();
tb=s.nextLine();
DateFormat sdf = new SimpleDateFormat("hh");
Date date1 = sdf.parse(ta);
Date date2 = sdf.parse(tb);
diff=sdf.format(date1)-sdf.format(date2);
if(diff==20)
System.out.println("Twenty");