system.date.format
Returns the given date as a string, formatted according to a pattern. The pattern is a format that is full of various placeholders that will display different parts of the date. These are case-sensitive! These placeholders can be repeated for a different effect. For example, M will give you 1-12, MM will give you 01-12, MMM will give you Jan-Dec, MMMM will give you January-December.
The placeholders are:
Symbol |
Description |
Presentation |
Examples |
Other Notes |
G |
Era designator |
G=AD |
|
|
y |
Year |
yyyy=1996; yy=96 |
Lowercase y is the most commonly used year symbol |
|
Y |
Week year |
YYYY=2009; YY=09 |
Capital Y gives the year based on weeks (ie. changes to the new year up to a week early) |
|
M |
Month in year |
MMMM=July; MMM=Jul; MM=07 |
|
|
w |
Week in year |
27 |
If Dec31 is mid-week, it will be in week 1 of the next year |
|
W |
Week in month |
2 |
|
|
D |
Day in year |
189 |
|
|
d |
Day in month |
10 |
|
|
F |
Day of week in month |
2 |
2nd Sunday of the month |
|
E |
Day name in week |
EEEE=Tuesday; E=Tue |
|
|
u |
Day number of week |
1 |
(1 = Monday, ..., 7 = Sunday) |
|
a |
Am/Pm marker |
PM |
|
|
H |
Hour in day (0-23) |
0 |
|
|
h |
Hour in am/pm (1-12) |
12 |
|
|
k |
Hour in day (1-24) |
24 |
|
|
K |
Hour in am/pm (0-11) |
0 |
|
|
m |
Minute in hour |
30 |
|
|
s |
Second in minute |
55 |
|
|
S |
Millisecond |
978 |
|
|
z |
Time zone |
zzzz=Pacific Standard Time; z=PST |
|
|
Z |
Time zone |
Z=-0800 |
|
|
X |
Time zone |
X=-08; XX=-0800; XXX=-08:00 |
|
Expert Tip: This function uses the Java class java.text.SimpleDateFormat internally, and will accept any valid format string for that class.
system.date. format( date, format )
-
Parameters
Date date- The date to format.
String format - A format string such as "yyyy-MM-dd HH:mm:ss".
-
Returns
String - A string representing the formatted datetime
-
Scope
All
#This example would format the current date to look like "01/01/01"
today
=
system.date.now()
print
system.date.
format
(today,
"yy/MM/dd"
)
#This printed 16/04/01
#This example would format the current date to look like "2001-01-31 16:59:59"
#This is a standard format that all databases recognize.
today
=
system.date.now()
print
system.date.
format
(today,
"yyyy-MM-dd HH:mm:ss"
)