I am using java 8 date and time classes in my code. I can find year, month, day, hours, minutes and seconds, but I cannot find a method to find a number of days in a month.
Here is my code.
I also want to iterate through “oldestDate” to “latestDate”. How can I iterate through “oldestDate” to “latestDate” until the “oldestDate” reaches to “latestDate”?
Here is my code.
Code:
String oldestDateString = "2015-10-01 00:00:00";
String latestDateString = "2015-12-25 00:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime oldestDate = LocalDateTime.parse(oldestDateString, formatter);
LocalDateTime latestDate = LocalDateTime.parse(latestDateString, formatter);
int year = oldestDate.getYear();
int month = oldestDate.getMonthValue();
int day = oldestDate.getDayOfMonth();
int hours = oldestDate.getHour();
int minutes = oldestDate.getMinute();
int seconds = oldestDate.getSecond();
Comment