The problem is as follows:
The application should display the work shift in the schedule for the selected date. To do this, it counts the number of days from a specific date, divides by 12 (the length of the cycle) and displays the remainder of the division.
On one device, the algorithm worked correctly. However, when installing the application to another device, an error appeared on one day.
String d1 = "02.11.1945"; Int year = mDatePicker.getYear(); Int month = mDatePicker.getMonth(); month = month + 1; Int day = mDatePicker.getDayOfMonth(); String d2 = (day +"." + month + "." + year); SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); Date date1 = null; Date date2 = null; try { date1 = format.parse(d1); date2 = format.parse(d2); } catch (Exception e) { e.printStackTrace(); } long difference = date2.getTime() - date1.getTime(); long days = difference / (24 * 60 * 60 * 1000); Long result = days%12; When I displayed the totals of all the variables in TextViev, it turned out that on different phones the days had a difference of one day.
Accordingly, the problem in calculating the difference .
Why this could be, and how to fix it?
(Date d1 is chosen randomly)
date1anddate2are they correct? - Boris Safonov