Signup/Sign In
LAST UPDATED: NOVEMBER 24, 2020

Java LocalDate parse() Method

Java LocalDate parse() method is used to get a localdate from the text date. It returns an instance of LocalDate from a text string such as 2007-12-03.

It can be used to convert a string type date to localdate instance. The string must represent a valid date in the format of ISO LocalDate. For example, 2015-02-10 is valid whereas 20-10-2015 is an invalid date string.

Syntax

public static LocalDate parse(CharSequence text)

Parameters:

It takes a single parameter of type string.

Returns:

It returns a local date after parsing string date.

Time for an Example:

Let's take an example to get a local date from string date. Here, we are using parse() method to parse a text sequence to get LocalDate instance.

import java.time.LocalDate;
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.parse("2015-12-10");
		System.out.println(localDate);		
	}
}


2015-12-10

Time for another Example:

Let's take another example to understand the parse() method that can be used to conver string to localdate. Notice, in this example, string date is parsed and converted to localdate object.

import java.time.LocalDate;
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.parse("2011-02-28");
		System.out.println(localDate);		
	}
}


2011-02-28

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.