Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2022); calendar.set(Calendar.MONTH, Calendar.DECEMBER); calendar.set(Calendar.DAY_OF_MONTH, 31); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999);
Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2021); calendar.set(Calendar.MONTH, Calendar.NOVEMBER); calendar.set(Calendar.DAY_OF_MONTH, 23); calendar.add(Calendar.HOUR_OF_DAY, 2); calendar.add(Calendar.MINUTE, 30);This code sets the calendar object to November 23, 2021, and adds 2 hours and 30 minutes to it. The java.util Calendar class is part of the java.base module in the Java standard library.