Created
October 19, 2018 03:20
-
-
Save hilfritz/00f085aecb6dcec9be5841b95bba22e5 to your computer and use it in GitHub Desktop.
java: jodatime get all datetime in month (including timezone)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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