I have JSONArray that have 57 JSONObjects, each object has 8 key/value pair properties. In which there is a “publishdate” property. I want to fetch each objects that has “publishdate” within a month.
Here is my code.
Which data structure is best for above scenario ArrayList or any other?
I have attach an image that shows JSONArray of JSONObjects.
Here is my code.
Code:
String startDateStr = "2015-10-01 00:00:00";
String endDateStr = "2015-12-25 00:00:00";
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime startDate = fmt.parseDateTime(startDateStr);
DateTime endDate = fmt.parseDateTime(endDateStr);
DateTime lastDateOfEachMonth; // This DateTime used for fetching each motn data.
int daysInMonth;
while (startDate.equals(endDate)) {
daysInMonth = startDate.dayOfMonth().getMaximumValue();
lastDateOfEachMonth = startDate.plusDays(daysInMonth - 1);
// Here i want to fetch data between the startDate to lastDateOfEachMonth. Means i want to make ArrayList of data from the
// "JSONArray" that contains only one month data. and put it the whole data to first index of the ArrayList.
// The data should be fetched according to publishdate.
startDate = lastDateOfEachMonth;
// This loop will until startDate reaches to endDate
}
I have attach an image that shows JSONArray of JSONObjects.