2015年12月11日 星期五

Formatting Time in APEX

Formatting Time in APEX

Here’s a table of format characters and what piece of the Date/Time object they display:
LetterDate or Time PieceExamples
GEraG = AD
yYearyy = 09, yyyy = 2009
MMonthMM = 08, MMM = Aug, MMMMM = August
wWeek in yearw = 35
WWeek in monthW = 3
DDay in yearD = 235
dDay in monthdd = 27
FDay of week in monthF = 2
EDay in weekE = Thu, EEEEE = Thursday
aAM/PMa = AM or PM
HHour in day (0-23)HH = 23
kHour in day (1-24)kk = 24
KHour in am/pm (0-11)KK=11
hHour in am/pm (1-12)hh = 12
mMinutes in hourmm = 30
sSecond in minutess = 55
SMillisecond in secondSSS = 888
zTime zonez = EDT, zzzzz = Eastern Daylight Time
ZTime zone offsetZ = -0400
So all that leaves to show is an example:
DateTime d = datetime.now();
timeStr = d.format(‘MMMMM dd, yyyy hh:mm:ss a’);

參考連結:https://paulforce.wordpress.com/2009/08/27/formatting-time-in-apex/

Formula 補充: https://help.salesforce.com/HTViewHelpDoc?id=formula_examples_dates.htm

沒有留言:

張貼留言