YearMonth withMonth(int month) example

Description

YearMonth withMonth(int month) returns a copy of this YearMonth with the month-of-year altered.

Syntax

withMonth has the following syntax.


public YearMonth withMonth(int month)

Example

The following example shows how to use withMonth.


import java.time.YearMonth;
//w w  w .  j a  v  a 2 s. com
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    YearMonth s = y.withMonth(3);
    System.out.println(s);

  }
}

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