package com.logicbig.example.yearmonth;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
public class ParseExample3 {
public static void main(String... args) {
DateTimeFormatter f = DateTimeFormatter.ofPattern("MMM-uuuu");
String text = "Jun-2017";
YearMonth ym = YearMonth.parse(text, f);
YearMonth now = YearMonth.now();
System.out.println(now);
int i = ym.compareTo(now);
System.out.printf("Is %s current month of year = %s%n", text, i == 0);
}
}
Output
2017-06
Is Jun-2017 current month of year = true