1
1
111ilya1112020-05-20 13:01:19
Java
111ilya111, 2020-05-20 13:01:19

What is the correct way to get the date from a string using java.time.*?

Hello!
There are lines like "some text dated 12/12/1990"
How to get this date correctly? whether to replace "." to "-" for that?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-05-20
@111ilya111

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
Stringdate = "12/12/1990";
LocalDate localDate = LocalDate.parse(date, formatter);
Parsing a string and extracting a date from it is a separate task, depending on the format. Regular expressions will help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question