Question

Currently Joda DateTime can get the current Android system time, but is it possible to get the DateTime when say the Android system date or timezone has changed?

I have tried this after the Date/Timezone has changed but it does not work:

DateTime dt = DateTime.now();
DateTime dt = new DateTime();

When I use the Calendar it works fine:

Calendar c = Calendar.getInstance();
c.getTime()  //Returns the correct changed Android Date and Time
Was it helpful?

Solution

As suggested by this post, you can get the Calendar time first:

public static int elapsedDaysJoda() {
  Calendar cal = Calendar.getInstance();
  DateTime dt1 = new DateTime(cal);
  cal.set(2011, 0, 1); 
  DateTime dt2 = new DateTime(cal.getTime());
  Days days = Days.daysBetween(dt2, dt1);
 return days.getDays();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top