Close

Java Date Time - LocalDate.withYear() Examples

Java Date Time Java Java API 


Class:

java.time.LocalDate

java.lang.Objectjava.lang.Objectjava.time.LocalDatejava.time.LocalDatejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.time.chrono.ChronoLocalDateChronoLocalDatejava.io.SerializableSerializableLogicBig

Method:

public LocalDate withYear(int year)

This method returns a new copy of this local date, with 'year' field replaced with the provided 'year' value.

If the provided year value is invalid, DateTimeException is thrown.


Examples


package com.logicbig.example.localdate;

import java.time.LocalDate;

public class WithYearExample {

public static void main (String... args) {
LocalDate d = LocalDate.of(2016, 7, 10);
LocalDate d1 = d.withYear(1990);
System.out.println(d1);
}
}

Output

1990-07-10




See Also