Java LocalDate now(Clock) Method

Java LocalDate now(Clock) method is used to get the current date based on the specified clock. The clock is an abstract class that provides static methods to create a date of various scenarios.

We can use Clock's methods to generate local date based on zone across the world.

It returns a local date from the specified clock. The syntax of the method is given below.

Syntax

public static LocalDate now(Clock clock)

Parameters:

It takes a single parameter of Clock type.

Returns:

It returns a local date

Time for an Example:

Let's take an example to create a current date using the best available system clock. Here, we are using systemUTC() method of Clock class for converting to date and time using the UTC time-zone.

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


2020-06-11

Time for another Example:

Let's take another example to get the current date. Here, we are using the systemDefaultZone() method that returns the current system default clock based date.

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


2020-06-11

Live Example:

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