The first (and therefore also the last) day of the week varies by locale (not by time zone nor GMT offset). A locale may define a country or region and/or a language. The language isn’t relevant (at least usually not), but the country is. For example Pakistan:
WeekFields wf = WeekFields.of(Locale.forLanguageTag("ur-PK"));
System.out.println("Last day of week is " + wf.getFirstDayOfWeek().plus(6));
Output is:
Last day of week is SATURDAY
Or United Arab Emirates, since you mentioned the Gulf (I assumed the Persian Gulf):
WeekFields wf = WeekFields.of(Locale.forLanguageTag("ar-AE"));
Last day of week is FRIDAY
To use the default locale, specify Locale.getDefault()
:
WeekFields wf = WeekFields.of(Locale.getDefault());
Since my locale is Denmark (Europe), I get Last day of week is SUNDAY
now.
I am using the WeekFields
class of java.time, the modern Java date and time API. The Calendar
class that you are using is poorly designed and long outdated, and the modern API offers a richer functionality.
What happened?
Possible explanations for the behaviour you have observed include:
- Your two devices have different country settings. I consider this the likely explanation. You have not told us the country setting of each device.
- On at least one device the JVM does not respect the device locale setting. It is possible to start a JVM with a locale setting that differs from that of the underlying system (not that I know how to do that on Android). It is also possible to change the locale setting of the JVM dynamically through one of the
Locale.setDefault
methods.
- Locale data have been changed between the Android versions of your devices, so for the country in question, one device thinks that the day starts on Sunday, on the other device Monday. Locale data are being updated all the time.
For getting the matter a little closer I would start by outputting Locale.getDefault().getDisplayCountry()
on each device.
Question: Can I use java.time on Android?
Yes, java.time works nicely on older and newer Android devices. It just requires at least Java 6.
- In Java 8 and later and on newer Android devices (from API level 26) the modern API comes built-in.
- In Java 6 and 7 get the ThreeTen Backport, the backport of the modern classes (ThreeTen for JSR 310; see the links at the bottom).
- On (older) Android use the Android edition of ThreeTen Backport. It’s called ThreeTenABP. And make sure you import the date and time classes from
org.threeten.bp
with subpackages.
Links