When I compile this code by compiler compliance level 6.0 in eclipse then it compile fine but when I change compiler level 4.0 then this code shows error that Incompatible Conditional operand types String and Integer. What is the problem and changes this code need to get the same result
Calendar cal = Calendar.getInstance();
String timeStr = (calendar.get(Calendar.HOUR_OF_DAY) < 10 ?
"0" + Integer.valueOf(calendar.get(Calendar.HOUR_OF_DAY)) :
Integer.valueOf(calendar.get(Calendar.HOUR_OF_DAY))) + ":" +
(calendar.get(Calendar.MINUTE) < 10 ?
"0" + Integer.valueOf(calendar.get(Calendar.MINUTE)) :
Integer.valueOf(calendar.get(Calendar.MINUTE)));
Why not just use
SimpleDateFormatto get the same result, like this:It works with the compiler compliance level set to 1.4.
Edit: for reference if
SimpleDateFormatdidn’t exist, I’d recommend writing it something like this: