How to get the current date in java


LocalDate ld =;

In java, the current Date can be accessed using the method now of the LocalDate object.


The example first creates a localDate object calling the now method of the LocaleDate object. That date is converted to a String using the format method and the ISO_DATE formatter that is part of the DateTimeFormatter Object. The String is then written in the output.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class CurrentDateTest {

    public static void main(String[] argv) {
	LocalDate ld =;

	System.out.println("Date in ISO format: " + ld.format(DateTimeFormatter.ISO_DATE));

The output will be:

Date in ISO format: 2018-08-13


Java LocalDate

Recent Comments