Try to use this:
public static void main(String[] args) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateInString = "2015-07-16 17:07:21";
try {
Date date = formatter.parse(dateInString);
System.out.println(date);
System.out.println(formatter.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
}
Output:
Thu Jul 16 17:07:21 IST 2015
2015-07-16 17:07:21
Note:
For complete date and time patterns, please refer to this http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html