Using java.util.Date Class

Simply create a new Date() object to get the current date and time. Use the following Java program, In this program, we also used DateTimeFormatter class to show results in proper formats as required.

Using java.util.Calendar Class

Use the function Calendar.getInstance() from Calendar class. This provides options for manipulating the calendar fields, such as getting the date of the next week or next month, etc. You can also use date time format class as above with the below examples.

Using the Calendar class, you can also find the date and time in the past or future. For example, what will the date after or before 10 days of the current date. Similarly, we can do the same for years, months, hours, minutes and seconds as well. Please find below a sample Java program.

Output: