Java Date Time - ZonedDateTime withYear(int year) example








ZonedDateTime withYear(int year) returns a copy of this ZonedDateTime with the year value altered.

Syntax

withYear has the following syntax.

public ZonedDateTime withYear(int year)

Example

The following example shows how to use withYear.

import java.time.ZonedDateTime;

public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime =ZonedDateTime.now();
    dateTime = dateTime.withYear(2000);
    System.out.println(dateTime);
  } 
}

The code above generates the following result.