Other answers are correct, for example, Franz Becker's Answer . But they use the old java.util.Date and java.text.SimpleDateFormat classes.
java.time
Here is similar code, but using the new java.time and java.time.format in Java 8 and later.
String parsing
The question presented two examples of input strings. Pay attention to various diacritics . The first works, but the second fails. I have no explanation, because I do not know this language ... "All this is Greek for me."; -)
String input1 = "25 Μαϊ 1989"; String input2 = "24 Μαΐ 1967";
Retrieve the Locale instance using the static Locale.forLanguageTag method new in Java 7. Specify the ISO 639 code (via IETF BCP 47 ) for Modern Greek .
Locale locale = Locale.forLanguageTag("el");
Indicate the exact template that we expect.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "dd MMM yyyy" ).withLocale( locale );
Parse using the recommended parse method, which takes a reference to the ( Tutorial ) method, LocalDate :: from , in the new Java 8 Lambda syntax.
LocalDate localDate1 = formatter.parse( input1, LocalDate :: from ); LocalDate localDate2 = formatter.parse( input2, LocalDate :: from ); // Fails… Exception in thread "main" java.time.format.DateTimeParseException: Text '24 Μαΐ 1967' could not be parsed at index 3.
Dump for the console.
System.out.println( "localDate1 = " + localDate1 );
At startup.
localDate1 = 1989-05-25
Line generation
To go another way to generate a localDate string representation, let java.time do the job of defining a localized format. Using automatic localization can be simpler and more flexible than hard-coding a particular format.
DateTimeFormatter formatterOutput = DateTimeFormatter.ofLocalizedDate( FormatStyle.MEDIUM ).withLocale( locale ); String output = formatterOutput.format( localDate1 ); System.out.println( "output = " + output );
Full month name
This second line of input with a different diacritic seems to be an inappropriate abbreviation for the full name of the month Μαΐου . Using this fully qualified month name with a different formatting (four characters of the M pattern) successfully analyzes. Again, I don’t know the modern Greek language, so this explanation is just an assumption from me and the people commenting on this answer.
This sample code demonstrates the successful parsing of input3 .
String input1 = "25 Μαϊ 1989"; String input2 = "24 Μαΐ 1967"; // Different diacritical over the "i". Incorrect abbreviation of full month name? String input3 = "23 Μαΐου 1978"; // Full month name with different diacritical. Locale locale = Locale.forLanguageTag( "el" ); DateTimeFormatter formatterShort = DateTimeFormatter.ofPattern( "dd MMM yyyy" ).withLocale( locale ); DateTimeFormatter formatterFull = DateTimeFormatter.ofPattern( "dd MMMM yyyy" ).withLocale( locale ); LocalDate localDate1 = formatterShort.parse( input1, LocalDate :: from ); // LocalDate localDate2 = formatter.parse( input2, LocalDate :: from ); // Fails… Exception in thread "main" java.time.format.DateTimeParseException: Text '24 Μαΐ 1967' could not be parsed at index 3. LocalDate localDate3 = formatterFull.parse( input3, LocalDate :: from ); System.out.println( "localDate1 = " + localDate1 ); System.out.println( "localDate3 = " + localDate3 );