java.time
You are using old troublesome date-time classes now supplanted by the java.time classes.
The java.time framework is built into Java 8 and later. These classes supplant the old troublesome date-time classes such as java.util.Date, .Calendar, & java.text.SimpleDateFormat. The Joda-Time team also advises migration to java.time.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations.
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP.
LocalDate
For date-only values, use the LocalDate class. Your input value is in standard ISO 8601 format. The ISO 8601 formats are used by default in java.time classes for parsing and generating strings that represent the date-time values. So no need to specify a formatting pattern.
LocalDate localDate = LocalDate.parse( "2012-03-05" );
To generate such a string, call toString.
String output = localDate.toString();
LocalDateTime
For a string such as 2012-03-05 12:34:56 we have a problem. No offset-from-UTC or time zone is indicated. So it does not represent an actual moment on the timeline, but rather a rough idea about possible moments. This non-moment is represented in java.time by the LocalDateTime class.
Your string’s format is a variation on ISO 8601 while the canonical version has a T in the middle rather than a space. So one option is to replace the SPACE with a T.
LocalDateTime ldt = LocalDateTime.parse( "2012-03-05 12:34:56".replace( " " , "T" );
Or define a pattern.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyy-MM-dd hh:mm:ss" );
LocalDateTime ldt = LocalDateTime.parse( "2012-03-05 12:34:56" , formatter );
Avoid using such date-time formats lacking in offset or time zone info if indeed they are meant to represent actual moments on the timeline.
ZonedDateTime
To give that value meaning, to determine an actual moment on the timeline, we need to assign the time zone for which the date-time is intended.
ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = ldt.atZone( zoneId );
Calling toString generates a String in a format that extends the ISO 8601 standard format by appending the name of the time zone in square brackets.
String output = zdt.toString(); // Yields: 2012-03-05T12:34:56-04:00[America/Montreal]
If you want to omit the T you could replace with a SPACE using String::replace method. Or use a formatter. If you really want a string as seen in the Question lacking any offset or time zone info (against my recommendation) use the same formatter shown above.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyy-MM-dd hh:mm:ss" ); // Not recommended as it lacks offset/zone info.
String output = zdt.format( formatter ); // Yields: 2012-03-05 12:34:56
sdf.parse("2012-03-05")