Assuming you are asking about Java, this link: https://www.mkyong.com/java/how-to-convert-string-to-date-java/ May help you.
The overall gist is:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestDateExample3 {
public static void main(String[] argv) {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dateInString = "26th May 2017"; // Remove your 'th', 'nd', etc. from the input string.
String withoutEnding = dateInString;
//Something like this
if(dateInString.contains("th") withoutEnding = dateInString.replace("th", "");
if(dateInString.contains("nd") withoutEnding = dateInString.replace("nd", "");
if(dateInString.contains("st") withoutEnding = dateInString.replace("st", "");
if(dateInString.contains("rd") withoutEnding = dateInString.replace("rd", "");
try {
Date date = formatter.parse(withoutEnding);
System.out.println(date);
System.out.println(formatter.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Where dd/MM/yyyy
is a date formatter that would give you
26/05/2017
.
Hope this helps!
EDIT: Also see http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html for a full list of the different pattern letters for SimpleDateFormat
.