Wednesday 3 April 2013


Salesforce Date & Datetime Formats
Salesforce uses the Java datetime formats, found here, for its format strings used with datetimes. The format() method only applies to datetimes; if you want to format a date, you must first convert it to a datetime using newInstance():

date testDate = system.today();
datetime dt = dt.newInstance(testDate, time.newInstance(0, 0, 0, 0));


The baseline datetime formats are as follows:

LetterDate or Time ComponentPresentationExamples
GEra designatorTextAD
yYearYear1996; 96
MMonth in yearMonthJuly; Jul; 07
wWeek in yearNumber27
WWeek in monthNumber2
DDay in yearNumber189
dDay in monthNumber10
FDay of week in monthNumber2
EDay in weekTextTuesday; Tue
aAm/pm markerTextPM
HHour in day (0-23)Number0
kHour in day (1-24)Number24
KHour in am/pm (0-11)Number0
hHour in am/pm (1-12)Number12
mMinute in hourNumber30
sSecond in minuteNumber55
SMillisecondNumber978
zTime zoneGeneral time zonePacific Standard Time; PST; GMT-08:00
ZTime zoneRFC 822 time zone-0800

Some interesting datetime formats are found in this table:
InputFormatOutput
07/05/2009MM/dd/yyyy07/05/2009
07/05/2009M/d/yy7/5/09
07/05/2009dd/MM//yyyy05/07/2009
07/05/2009MMMM d, yyyyJuly 5, 2009
07/05/2009EEEESunday

Categories: ,

1 comment:

    Links