Calendar calendar = Calendar.getInstance(); Date currentDate = calendar.getTime();
Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.WEEK_OF_YEAR, 2); Date newDate = calendar.getTime();
Calendar calendar = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = sdf.format(calendar.getTime());This code snippet formats the current date in the calendar into a string in the yyyy-MM-dd format. Overall, the java.util Calendar class is a useful tool for working with dates and times in Java programs. Its functionality can be further enhanced by using other related classes in the java.time package, which provides more advanced date and time manipulation capabilities.