Year atMonth(Month month) method in Java
Last Updated :
27 Nov, 2018
The atMonth(Month) method of Year class in Java combines the current year object with a month passed as parameter to it to create a YearMonth object.
Syntax:
public YearMonth atMonth(Month month)
Parameter: This method accepts a single parameter month. It is the month-of-year to use. It takes a valid Month object and cannot be NULL.
Return Value: It returns a YearMonth object formed by the current year object and a valid month passed as parameter to the function.
Below programs illustrate the atMonth(Month month) method of Year in Java:
Program 1:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 2017 );
YearMonth yearMonth = thisYear.atMonth(Month.SEPTEMBER);
System.out.println(yearMonth);
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
Year thisYear = Year.of( 2018 );
YearMonth yearMonth = thisYear.atMonth(Month.JANUARY);
System.out.println(yearMonth);
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#atMonth-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...