Java Date Time Java Java API
java.time.LocalDateTime
public LocalDateTime withYear(int year)
Returns a copy of this LocalDateTime with the year field replaced with the specified year value.
package com.logicbig.example.localdatetime;import java.time.LocalDateTime;public class WithYearExample { public static void main (String... args) { LocalDateTime d = LocalDateTime.of(2000, 1, 2, 10, 20, 30); System.out.println(d); LocalDateTime d2 = d.withYear(2015); System.out.println(d2); }}
2000-01-02T10:20:302015-01-02T10:20:30