I have a small application which simply sets the time and date of a Calendar and then retrieves it.
Currently when using my application on devices up to API24 its retrieves the correct date which was originally set. But if you run the application on a device higher than API 24 then the date returned is one day later than the desired result.
My code as below
Setting the date of the calendar....
myCalendar.set(Calendar.YEAR, 2018 );
myCalendar.set(Calendar.DAY_OF_MONTH, 3);
myCalendar.set(Calendar.MONTH, 0);
myCalendar.set(Calendar.HOUR, 18);
myCalendar.set(Calendar.MINUTE, 30);
Retrieving the date
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String dates = sdf.format(myCalendar.getTime());
StringTokenizer revDate = new StringTokenizer(dates, "/");
String txtDays = revDate.nextToken();
String txtMonths = revDate.nextToken();
String txtYears = revDate.nextToken();
String reversedDate = txtDays + txtMonths + txtYears;
On phones below API 24 we receive the correct date 03/01/2018 on API 24 above I receive 04/01/2018
I've tested my application on multiple virtual devices and real phones, all using the same time zone its only when using API 24 above that this strange issue occurs.
Thanks