Java LocalDate now(ZoneId) Method

Java LocalDate now(ZoneId) method is used to obtain the current date from the system clock in the specified time-zone. It returns the current local date with the specified time-zone.

A time zone is a region of a city or country that observes a uniform standard time. For example, Asia/Kolkata, Asia/Chennai, etc.

This method takes an argument as ZoneId to specify the time-zone and returns a local date. The syntax of the method is given below.

Syntax

public static LocalDate now(ZoneId zone)

Parameters:

It takes a single parameter of ZoneId.

Returns:

It returns a local date.

Time for an Example:

Here, we are getting the current date with default system time-zone. We used systemDefault() method of ZoneId to get default time-zone.

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


2020-06-12

Time for another Example:

If we want a different time-zone date than system default then we can pass time-zone by using the of() method. It returns the date based on the specified time-zone.

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


2020-06-12

Live Example:

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