Formatting Time in APEX
Here’s a table of format characters and what piece of the Date/Time object they display:
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 |
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
沒有留言:
張貼留言