You need to parse the date string first (use DateFormat#parse() ) to get the Date using a format that matches the date string format.
And then format this Date object (use DateFormat#format() ), using the required format in SimpleDateFormat to get the string.
String time = "2012-12-08 13:39:57 +0000"; Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(time); String str = new SimpleDateFormat("dd MMM yyyy HH:mm:ss").format(date); System.out.println(str);
Result: -
08 Dec 2012 19:09:57
Z in the first format for RFC 822 TimeZone to match +0000 in your date string. See SimpleDateFormat for various other parameters that will be used in your date format.
source share