Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert string to german date java

my problem is the following. I would like to have the german date for the string "11.11.2012".

I tried this piece of code:

String date = "11.11.2012";
SimpleDateFormat sdtF = new SimpleDateFormat("dd.mm.yyyy",Locale.GERMANY);
Date dareFormatiert = sdtF.parse(date);
System.out.println(dareFormatiert);

But it gives me the wrong format. "Wed Jan 11 00:11:00 CET 2012", instead of "11.11.2012".

Thank you, any help is appreciated.

like image 471
Hellgamer Avatar asked Sep 19 '26 15:09

Hellgamer


1 Answers

You have to use M in you pattern, because M is the month and m is the minute!

String date = "11.11.2012";
SimpleDateFormat sdtF = new SimpleDateFormat("dd.MM.yyyy",Locale.GERMANY);
                                                ^^^^
Date dareFormatiert = sdtF.parse(date);
System.out.println(dareFormatiert);

For more information see the documentation of SimpleDateFormat

like image 95
Jens Avatar answered Sep 21 '26 06:09

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!