fork download
  1. import java.time.Year;
  2. import java.time.YearMonth;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. // Sample year and month strings
  7. String strYear = "2022";
  8. String strMonth = "9";
  9. YearMonth ym = Year.of(Integer.parseInt(strYear))
  10. .atMonth(Integer.parseInt(strMonth));
  11. System.out.println(ym);
  12.  
  13. // Comparing two instances of YearMonth
  14. YearMonth currentYm = YearMonth.now();
  15. if (ym.isAfter(currentYm))
  16. System.out.println(ym + " is after " + currentYm);
  17. else
  18. System.out.println(ym + " is before or equal to " + currentYm);
  19. }
  20. }
  21.  
Success #stdin #stdout 0.16s 53632KB
stdin
Standard input is empty
stdout
2022-09
2022-09 is before or equal to 2023-01