Letter Date or Time Piece Examples
G Era G = AD
y Year yy = 09, yyyy = 2009
M Month MM = 08, MMM = Aug, MMMMM = August
w Week in year w = 35
W Week in month W = 3
D Day in year D = 235
d Day in month dd = 27
F Day of week in month F = 2
E Day in week E = Thu, EEEEE = Thursday
a AM/PM a = AM or PM
H Hour in day (0-23) HH = 23
k Hour in day (1-24) kk = 24
K Hour in am/pm (0-11) KK=11
h Hour in am/pm (1-12) hh = 12
m Minutes in hour mm = 30
s Second in minute ss = 55
S Millisecond in second SSS = 888
z Time zone z = EDT, zzzzz = Eastern Daylight Time
Z Time zone offset Z = -0400

Example :
DateTime d = datetime.now();
dateTimeVal = d.format(‘MMMMM dd, yyyy hh:mm:ss a’);
Output :
April 04, 2012 02:40:50 AM

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *