Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why I don tcan parse "01-01-2000" to 01.jan.2000 (LocalDate)? (Java)

Hello my brothers from another mothers!
When I have

the String "01-01-2000" I can easy parse it to locale date with DateTimeFormatter.ofPattern("d-MM-yyyy")
In combination with Localdate.parse("01-01-2000",DateTimeFormatter.ofPattern("d-MM-yyyy") it works.

But! When I want it to make 01.jan.2000 it dont work!
I tried it so:
LocalDate variablle=Localdate.parse("01-01-2000",DateTimeFormatter.ofPattern("d-MjMM-yyyy")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Normally MMM should show it now with the month name…

But It dont work!

>Solution :

jan will not work, the only way you can do this is with Jan (mind the uppercase of the first letter). The following works:

LocalDate variable = LocalDate.parse("01.Jan.2000", DateTimeFormatter.ofPattern("dd.MMM.yyyy"));

It seems that what you want is to format a LocalDate variable after parsing a plain String. The following is what you are looking for:

LocalDate date = LocalDate.parse("01-01-2000", DateTimeFormatter.ofPattern("dd-MM-yyyy"));
System.out.println(date.format(DateTimeFormatter.ofPattern("dd.MMM.yyyy")));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading