LocalDate parse(CharSequence text, DateTimeFormatter formatter)
returns an instance of LocalDate from a text string using a specific formatter.
parse
has the following syntax.
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter)
The following example shows how to use parse
.
import java.time.LocalDate; import java.time.format.DateTimeFormatter; /*from ww w.j a v a2 s.co m*/ public class Main { public static void main(String[] args) { LocalDate a = LocalDate.parse("20140630",DateTimeFormatter.BASIC_ISO_DATE); System.out.println(a); } }
The code above generates the following result.
The following code shows how to parse 'Jan 20 2014' to LocalDate.
// w w w . ja v a 2s .c om import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class Main { public static void main(String[] args) { String input = "Jan 20 2014"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy"); LocalDate date = LocalDate.parse(input, formatter); System.out.printf("%s%n", date); } }
The code above generates the following result.