If you need to get today’s date in Java, then you can do one of the following:

Option 1 – Using LocalDate

1
2
3
4
5
6
7
8
import java.time.LocalDate;

public class GetTodayDate {
    public static void main(String[] args) {
        LocalDate todaysDate = LocalDate.now();
        System.out.println(todaysDate);
    }
}

Option 2 – Using Calendar and SimpleDateFormat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class GetTodayDate {
    public static void main(String[] args) {
        SimpleDateFormat dtf = new SimpleDateFormat("yyyy/MM/dd");
        Calendar calendar = Calendar.getInstance();

        Date dateObj = calendar.getTime();
        String formattedDate = dtf.format(dateObj);
        System.out.println(formattedDate);
    }
}

Option 3 – Using java.sql.Date

1
2
3
4
5
6
7
8
9
import java.sql.Date;

public class GetTodayDate {
    public static void main(String[] args) {
        long miliseconds = System.currentTimeMillis();
        Date date = new Date(miliseconds);
        System.out.println(date);
    }
}