I was checking the code I wrote a few years ago. Then I realised that Android Studio is giving an annotation at Calendar.AM
, it says it must be one of Calendar.SUNDAY
, Calendar.MONDAY
and so on...
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.add(Calendar.MINUTE, -90 * (pos + 1) - 14);
hour = c.get(Calendar.HOUR);
minute = c.get(Calendar.MINUTE);
boolean am = (c.get(Calendar.AM_PM) == Calendar.AM);
if (hour == 0) hour = 12;
String time = hour + ":";
time += (minute < 10) ? "0" + minute : minute;
time += (am) ? " AM" : " PM";
return time;
I just want to make a boolean check whether it's AM or PM and set the time accordingly. The program is working though.
Had the same problem with some legacy code I am currently working on.
I found this issue being tracked here: https://issuetracker.google.com/issues/37122723
However, it seems like they won't be fixing it as it comes from IntelliJ: https://youtrack.jetbrains.com/issue/IDEA-144891
It shouldn't affect your code though, as it is only a code analysis/inspection bug.