• Source
    1. /* package whatever; // don't place package name! */
    2.  
    3. import java.time.LocalDate;
    4. import java.time.format.DateTimeFormatter;
    5. import java.time.temporal.IsoFields;
    6. import java.time.temporal.TemporalAdjusters;
    7.  
    8. /* Name of the class has to be "Main" only if the class is public. */
    9. class Ideone
    10. {
    11. static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-uu");
    12.  
    13. public static void main (String[] args)
    14. {
    15. String str = "30-09-20";
    16. LocalDate date = LocalDate.parse(str, dateFormatter);
    17.  
    18. // Is date the end of a quarter?
    19. if (date.get(IsoFields.DAY_OF_QUARTER) >= 90
    20. && date.equals(date.with(TemporalAdjusters.lastDayOfMonth()))) {
    21. LocalDate endOfNextQuarter = date.plus(1, IsoFields.QUARTER_YEARS)
    22. .with(TemporalAdjusters.lastDayOfMonth());
    23. System.out.println("End of next quarter is: " + endOfNextQuarter);
    24. System.out.println("End of next quarter is: "
    25. + endOfNextQuarter.format(dateFormatter));
    26. } else {
    27. throw new IllegalStateException(str + " is not a quarter end date");
    28. }
    29. }
    30. }