Signup/Sign In
LAST UPDATED: NOVEMBER 24, 2020

Java LocalDate now() Method

Java LocalDate now() method is used to get the current local date. It returns the default system date based on the locale.

We can use it to obtain the current date from the system clock in the default time-zone. It belongs to the Java LocalDate class and returns the current date. The syntax of the method is given below.

Syntax

public static LocalDate now()

Parameters:

It does not take any parameter.

Returns:

It returns a local-date.

Time for an Example:

Let's take an example to get the current local date. Here, we are using the now() method that returns the current date based on the locale.

import java.time.LocalDate; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.now();
		System.out.println(localDate);
	}
}


2020-06-11

Time for another Example:

Let's take another example to get current date. Here, we are using format method also to get current date in the desired format. See the example below.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.now();	
		System.out.println(localDate);
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/YYYY");
        String date = formatter.format(localDate);
        System.out.println("New date : "+date);
	}
}


2020-06-11
New date : 11/06/2020

Live Example:

Try with a live example, execute the code instantly with our powerful Online Java Compiler.



About the author:
I am a 3rd-year Computer Science Engineering student at Vellore Institute of Technology. I like to play around with new technologies and love to code.