0

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
Ash
  • 1,241
  • 1
  • 9
  • 16
  • The following link (http://stackoverflow.com/a/8713654/1012381) suggests using LocalDate instead of DateTime. – JScoobyCed Aug 14 '13 at 06:17
  • @JScoobyCed Thanks for the link, just had a look and tried the code, it works great. Can you put this up as the answer so I can accept it? – Ash Aug 15 '13 at 07:43

1 Answers1

1

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();
}
Community
  • 1
  • 1
JScoobyCed
  • 10,203
  • 6
  • 34
  • 58