Close

Java Date Time - Year.atMonth() Examples

Java Date Time Java Java API 


Class:

java.time.Year

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

Methods:

public YearMonth atMonth(Month month)

The method combines the copy of this year object with the specified month to create a YearMonth.



public YearMonth atMonth(int month)

The method combines the copy of this year object with the specified value of month int to create a YearMonth.


Examples


package com.logicbig.example.year;

import java.time.Year;
import java.time.YearMonth;

public class AtMonthExample {

public static void main(String... args) {
Year y = Year.of(2011);
System.out.println(y);

YearMonth ym = y.atMonth(10);
System.out.println(ym);
}
}

Output

2011
2011-10




package com.logicbig.example.year;

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

public class AtMonthExample2 {

public static void main(String... args) {
Year y = Year.of(2011);
System.out.println(y);

YearMonth ym = y.atMonth(Month.SEPTEMBER);
System.out.println(ym);
}
}

Output

2011
2011-09




See Also