Year atMonth(int month) example

Description

Year atMonth(int month) combines this year with a month to create a YearMonth.

Syntax

atMonth has the following syntax.


public YearMonth atMonth(int month)

Example

The following example shows how to use atMonth.


import java.time.Year;
import java.time.YearMonth;
//from   ww  w. ja v a 2 s  .c  om
public class Main {
  public static void main(String[] args) {
    Year y = Year.of(2014);
    YearMonth l = y.atMonth(1);
    System.out.println(l);

  }
}

The code above generates the following result.

Example 2

The following code shows how to create LocalDate from month and day and current year.


import java.time.LocalDate;
import java.time.Month;
import java.time.Year;
/* w ww  .  j a  v  a2 s . c  o m*/
public class Main {
  public static void main(String[] args) {
    Month month = Month.valueOf("January".toUpperCase());

    LocalDate date = Year.now().atMonth(month).atDay(12);

    System.out.println(date);
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset