Other answers, such as one by user2663609 , are correct.
Alternatively, the open source replacement of the third part for the java.util.Date/Calendar classes, Joda-Time , includes a built-in format for your needs.
Dump for console ...
System.out.println( "dateTime: " + dateTime.toString() ); System.out.println( "stringOut: " + stringOut );
At startup ...
dateTime: 2011-04-07T00:00:00.000+01:00 stringOut: 2011-04-07
Basil bourque
source share