javatimeYearMonth
javatimeYearMonth is a class in the java.time package introduced in Java 8 as part of the Date and Time API. It represents a specific year and month without a day component, such as 2024‑01 for January 2024. This class is immutable and thread‑safe, making it suitable for concurrent applications that need to manipulate dates at the year‑month level.
The primary constructor is YearMonth.of(int year, int month), where month is either an int between 1 and 12 or
YearMonth provides arithmetic operations such as plusYears, plusMonths, minusYears and minusMonths, enabling chronological calculations over months.
Comparison methods include isBefore, isAfter, and compareTo, facilitating sorting of YearMonth instances. Equality and hash code
Formatting is achieved via DateTimeFormatter. The built‑in formatters, such as ISO_DATE, produce strings like “2024‑01”. Custom
Because YearMonth contains no time‑zone information, it is unaffected by daylight‑saving time transitions or locale changes.