formatDate(date, string)
Formats a date according to a simple date format and returns the result as a string.
Parameters
date a java or javascript date object
format string The format follows the Java
SimpleDateFormat specification
Example
formatDate(new Date(), "hh 'o''clock' a, zzzz");
The date format uses the same syntax as in java.text.SimpleDateFormat.
A format string can be constructed using the characters listed in the table below.
Symbol |
Meaning |
Presentation |
Example |
G |
era designator |
Text |
AD |
y |
year |
Number |
1996 |
M |
month in year |
Text & Number |
July & 07 |
d |
day in month |
Number |
10 |
h |
hour in am/pm (1~12) |
Number |
12 |
H |
hour in day (0~23) |
Number |
0 |
m |
minute in hour |
Number |
30 |
s |
second in minute |
Number |
55 |
S |
millisecond |
Number |
978 |
E |
day in week |
Text |
Tuesday |
D |
day in year |
Number |
189 |
F |
day of week in month |
Number |
2 (2nd Web in July) |
w |
week in year |
Number |
27 |
W |
week in month |
Number |
2 |
a |
am/pm marker |
Text |
PM |
k |
hour in day (1~24) |
Number |
24 |
K |
hour in am/pm (0~11) |
Number |
0 |
z |
time zone |
Text |
Pacific Standard Time |
' |
escape for text |
Delimiter |
|
'' |
single quote |
Literal |
' |
Pattern letters can be repeated to obtain the desired date format. For the symbols marked as 'Text' for its presentation, if the number of pattern letters is 4 or more, the fill form is used; otherwise a short or abbreviated form is used if available. For the symbols marked as 'Number' for its presentation, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount.
Some examples are shown below:
Date and time pattern |
result |
“yyyy.MM.dd G 'at' HH:mm:ss z” |
2006.08.07 AD at 02:19:35 PDT |
“EEE, MMM d, ' ' yy” |
Mon, Aug 7, '06 |
“h:mm a” |
12:08 PM |
“hh 'o' 'clock' a, zzzz” |
12 o'clock PM, Pacific Daylight Time |
| << JS.1 Global Object Functions | © 1996-2013 InetSoft Technology Corporation (v11.4) | formatNumber(number, string, string) >> |