Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hilfritz/00f085aecb6dcec9be5841b95bba22e5 to your computer and use it in GitHub Desktop.
Save hilfritz/00f085aecb6dcec9be5841b95bba22e5 to your computer and use it in GitHub Desktop.
java: jodatime get all datetime in month (including timezone)
public static final ArrayList<DateTime> getAllDateTimeInMonth(int month, int year, String timezoneID){
Log.d(TAG, "getAllDateTimeInMonth: month:"+month);
DateTimeZone dateTimeZone = DateTimeZone.forID(timezoneID);
DateTime dateTime = new DateTime(year, month, 1,0, 0, dateTimeZone);
Log.d(TAG, "getAllDateTimeInMonth: month:"+month+" year:"+year);
ArrayList<DateTime> daysInMonthLabels = new ArrayList<DateTime>();
DateTime lastMonthLastDay = dateTime.minusMonths(1).dayOfMonth().withMaximumValue();
DateTime nextMonthFirstDay = dateTime.dayOfMonth().withMaximumValue();
while (lastMonthLastDay.isBefore(nextMonthFirstDay)) {
lastMonthLastDay = lastMonthLastDay.plusDays(1);
daysInMonthLabels.add(lastMonthLastDay);
}
return daysInMonthLabels;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment