import java.util.Calendar; import java.util.Date; public class SetTimeExample{ public static void main(String[] args){ Calendar calendar = Calendar.getInstance(); Date systemTime = new Date(); calendar.setTime(systemTime); System.out.println("Calendar Time: " + calendar.getTime()); } }
import java.util.Calendar; import java.util.Date; public class SetTimeExample{ public static void main(String[] args){ Calendar calendar = Calendar.getInstance(); Date specificTime = new Date(121, 0, 1, 12, 30, 0); // January 1, 2021 12:30:00 PM calendar.setTime(specificTime); System.out.println("Calendar Time: " + calendar.getTime()); } }This method is part of the java.util package library.