You can use the format function to format the datetime in any format. Following example shows the created date retrieved in yyyy-mm-dd hh:mm:ss format.
String createdDate = contactObj.CreatedDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'z\'');