I want to get the first day of the week but I have a strange bug. If I use this code:
Calendar cal = Calendar.getInstance();
cal.set(2017, 0, 1);
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault());
Log.d(TAG, "Date: " + dateFormat.format(cal.getTime()));
My log displays the wrong date: D/Activity: Date: lundi 2 janvier 2017
But if I use the getTime()
method just like this:
Calendar cal = Calendar.getInstance();
cal.set(2017, 0, 1);
cal.getTime(); // Here
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault());
Log.d(TAG, "Date: " + dateFormat.format(cal.getTime()));
My log display the correct date: D/Activity: Date: lundi 26 décembre 2016
My phone uses the French language so my week begins on Monday.
Somebody knows why?