Reputation: 327
Why does Calendar
in Android give different dates on different Android devices?
I did get the default locale and still I have the same problem.
Code:
calendar = Calendar.getInstance();
currentDate = DateFormat.getDateInstance(DateFormat.DATE_FIELD,Locale.getDefault())
.format(calendar.getTime());
Upvotes: 0
Views: 121
Reputation: 86148
Why does Calendar in android gives different dates in different android devices?
Calendar.getInstance
uses the system clock, so if the clocks of the different devices is set differently, you will get different times.That said, the Calendar
and DateFormat
classes have quite heavy design problems, and I consider them long outdated. If you are doing any considerable work with dates or times in your app, you should probably use java.time instead. It is the modern Java date and time API, much better designed and so much nicer to work with.
Yes, java.time works nicely on older and newer Android devices. It just requires at least Java 6.
org.threeten.bp
with subpackages.java.time
.java.time
was first described.java.time
to Java 6 and 7 (ThreeTen for JSR-310).Upvotes: 1