Retriving datetime field value in yyyy-mm-dd hh:mm:ss format

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\'');

Published by Sandeep Kumar

He is a Salesforce Certified Application Architect having 11+ years of experience in Salesforce.

Leave a Reply