How to get current date in java

This example shows you how to get the current date in java; we are using the SimpleDateFormat for getting the Date in String format.

package com.java.connect.date;
 
import java.text.SimpleDateFormat;
import java.util.Calendar;
 
public class CurrentDateExample {
 
    public static void main(String[] args) {
        // Get the simple date format object by passing the format in string
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        // get the date in String format by passing current date
        // in format method of simple date format object
        Calendar date = Calendar.getInstance();
        String dateString = format.format(date.getTime());
        // Print the formated date.
        System.out.println(dateString);
    }
}

The output of above example will be as:

07/05/2011