Close

Java Date Time - YearMonth.of() Examples

Java Date Time Java Java API 


Class:

java.time.YearMonth

java.lang.Objectjava.lang.Objectjava.time.YearMonthjava.time.YearMonthjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static YearMonth of(int year,
                           Month month)

Obtains an instance of YearMonth from specified int year and Month values.



public static YearMonth of(int year,
                           int month)

Obtains an instance of YearMonth from specified int year and int month values.


Examples


package com.logicbig.example.yearmonth;

import java.time.Month;
import java.time.YearMonth;

public class OfExample {

public static void main(String... args) {
YearMonth y = YearMonth.of(2010, Month.AUGUST);
System.out.println(y);
}
}

Output

2010-08




package com.logicbig.example.yearmonth;

import java.time.YearMonth;

public class OfExample2 {

public static void main(String... args) {
YearMonth y = YearMonth.of(2005, 4);
System.out.println(y);
}
}

Output

2005-04




See Also