Formats a date object according to the input mask.

Syntax

JSV_formatDate(expD [, mask])

Prototype

expD.formatDate([mask])

Returns

Returns a string-formated date/time value according to the input mask. If no mask is specified, the formatDate function returns a string-formated date/time value using the dd-mmm-yy format.

Parameters

The formatDate function uses the following arguments.

Argument Description
expD A date object.
mask Optional. Set of characters that are used to show how the date should be displayed. Default value is a dd-mmm-yy.

Remarks

Number format codes for dates

To display days, months, and years, include the following format codes in a section.

To display Use this format code
Months as 1-12 m
Months as 01-12 mm
Months as Jan-Dec mmm
Months as January-December mmmm
Days as 1-31 d
Days as 01-31 dd
Days as Sun-Sat ddd
Days as Sunday-Saturday dddd
Years as 00-99 yy
Years as 1970-2078 yyyy

Number format codes for times

To display hours, minutes, and seconds, include the following format codes in a section.

To display Use this format code
Hours as 0-23 h
Hours as 00-23 hh
Minutes as 0-59 m
Minutes as 00-59 mm
Seconds as 0-59 s
Seconds as 00-59 ss
Hours as 4 AM h AM
Time as 4:36 pm h:mm pm
Time as 4:36:03 p h:mm:ss p

If the format contains an AM or PM, the hour is based on the 12-hour clock, where AM, am, A, or a indicates times from midnight until noon, and PM, pm, P, or p indicates times from noon until midnight. Otherwise, the hour is based on the 24-hour clock. If m or mm is immediately preceded or followed by a ':', formatDate displays the minute; otherwise, the month is displayed.

Dependencies

JSV_toString, JSV_allowInString, JSV_parseString, JSV_getFullYear

Example

The following lines of code

var myDate = new Date();
document.write( myDate.formatDate("mm/dd/yyyy hh:mm:ss") );
document.write( myDate.formatDate("mm/dd/yyyy h:mm:ss am") );
document.write( myDate.formatDate("mmmm d, yyyy hh:mm:ss am") );
document.write( myDate.formatDate("d mmmm yyyy hh:mm") );

produce