fork download
  1. /* package whatever; // don't place package name! */
  2. import java.time.LocalDate;
  3. import java.time.format.DateTimeFormatter;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. // arguments are passed using the text field below this editor
  9. public static void main(String[] args)
  10. {
  11. String[]strs = {"1st-May-2013", "10th-Jun-2002", "2nd-Apr-1996"};
  12.  
  13. for(String str : strs){
  14. LocalDate d = ordinalStringToDate(str);
  15. System.out.println(d);
  16. }
  17. }
  18. private static LocalDate ordinalStringToDate(String str){
  19. return LocalDate.parse(str.replaceAll("(st|nd|rd|th)", ""), DateTimeFormatter.ofPattern("d-MMM-yyyy"));
  20. }
  21. }
Success #stdin #stdout 0.24s 35636KB
stdin
Standard input is empty
stdout
2013-05-01
2002-06-10
1996-04-02