Date date = new Date();//create date object System.out.println(date.toString());//print the string representation of date
Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); String formattedDate = formatter.format(date); System.out.println("Formatted Date: " + formattedDate);Output: Formatted Date: 09/08/2021 In this example, we have used the `SimpleDateFormat` class to format the date in the desired format. The `format()` method of this class takes a `Date` object as input and returns a string representation of the date in the specified format. Package Library: `java.text` and `java.util`