Unfortunately, the accepted answer has missed a crucial thing, Locale while parsing the date-time string. Therefore, that code will work merely by coincidence - only when the JVM on which it is executed, has an English Locale set. Check Always specify a Locale with a date-time formatter for custom formats to learn more about it.
java.time
In March 2014, Java 8 introduced the modern, java.time date-time API which supplanted the error-prone legacy java.util date-time API. Any new code should use the java.time API.
Solution using modern date-time API
Your date-time string has a time zone offset. So, parse your date-time string into an OffsetDateTime using DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss OOOO uuuu", Locale.ENGLISH) and format it using DateTimeFormatter.ofPattern("dd-MM-uuuu", Locale.ENGLISH).
Demo:
public class Main {
private static final DateTimeFormatter parser = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss OOOO uuuu",
Locale.ENGLISH);
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-uuuu",
Locale.ENGLISH);
public static void main(String[] args) {
OffsetDateTime odt = OffsetDateTime.parse("Mon Oct 20 00:00:00 GMT+06:30 2014", parser);
System.out.println(odt);
// Formatted output
System.out.println(odt.format(formatter));
}
}
Output:
2014-10-20T00:00+06:30
20-10-2014
Online Demo
Note: For whatever reason, if you need an instance of java.util.Date from this object of OffsetDateTime, you can do so as follows:
java.util.Date date = Date.from(odt.toInstant());
Learn more about the modern date-time API from Trail: Date Time.
formatter_date?