ZonedDateTime withYear(int year) example
Description
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;
//from w ww . j a v a 2 s .com
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.