I need to get local time in my app. I am using Calendar class for this purpose.
Code :
Calendar calendar = Calendar.getInstance();
calendar.get(Calendar.HOUR_OF_DAY)
shows the hours according to GMT.
I checked that TimeZone.getDefault().getDisplayName()
shows GMT (which is incorrect) as default timezone but java.util.TimeZone.getDefault().getDisplayName()
shows the correct timezone.
Also calendar.getTime().toString()
shows the correct time.
I do not understand why there is this discrepancy between android.icu.util.TimeZone
and java.util.TimeZone
Edit:
I recently found that there are two Calendar APIs - java.util.Calendar (added in API level 1) and android.icu.util.Calendar (added in API level 24).
I had been using android.icu.util.Calendar but tested it on Android M. So now I'll be using API java.util.Calendar