|
Date.format Method
Formats a date according to a specific, user-defined format.
object.format (DateFormat)
Arguments
- object
- Required. Always the name of a Date object.
- DateFormat
- Required. A string that defines the output format using the codes shown in
Settings. Other characters in DateFormat are interpreted literally.
Settings
The Date.format method uses the following formatting codes:
Use this code |
To display |
As |
yy |
Years |
00-99 |
yyyy |
Years |
1900-9999 |
m |
Months |
1-12 |
mm |
Months |
01-12 |
mmm |
Months |
Jan-Dec |
mmmm |
Months |
January-December |
d |
Days |
1-31 |
dd |
Days |
01-31 |
ddd |
Days |
Sun–Sat |
dddd |
Days |
Sunday–Saturday |
h |
Hours |
1–24 |
hh |
Hours |
01–24 |
n |
Minutes |
1–60 |
nn |
Minutes |
01–60 |
s |
Seconds |
1–60 |
ss |
Seconds |
01–60 |
A/P |
12-hour time |
A or P |
AM/PM |
12-hour time |
AM or PM |
Return Value
The Date.format method returns a string representing the Date
formatted according to the formatting pattern specified in DateFormat.
Remarks
The following example illustrates the use of the Date.format method.
var d = new Date("8/25/1983");
Alert(d.format("yyyymmdd"));
// displays "19830825" in an Alert box
Requirements
|