import java.util.Date; public class Main { public static void main(String[] args) { Date currentDate = new Date(); // create a new Date object representing the current date and time currentDate.setYear(122); // set the year value to 2022, which is 1900 + 122 System.out.println(currentDate); // prints something like "Sat Jan 01 04:56:24 EST 2022" } }
import java.util.Date; public class Main { public static void main(String[] args) { long specificTimeValue = 1640995200000L; // a time value representing "2022-01-01 00:00:00" Date specificDate = new Date(specificTimeValue); // create a new Date object from the specific time value specificDate.setYear(122); // set the year value to 2022 System.out.println(specificDate); // prints something like "Sat Jan 01 00:00:00 EST 2022" } }As mentioned earlier, the setYear method belongs to the java.util.Date class, which is part of the Java Standard Library. Therefore, no external package or library is required.