Calendar calendar = Calendar.getInstance(); Date currentDate = calendar.getTime();
Calendar calendar = Calendar.getInstance(); calendar.set(2022, Calendar.JANUARY, 1, 0, 0, 0); Date date = calendar.getTime();
Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 7); // Adds 7 days Date date = calendar.getTime();
Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.set(2021, Calendar.MAY, 20); cal2.set(2021, Calendar.JUNE, 1); int result = cal1.compareTo(cal2);Overall, the java.util.Calendar package library provides a lot of flexibility in manipulating dates and times in Java.