jQuery: The Write Less, Do More JavaScript Library

UI/Datepicker/$.datepicker.formatDate

From jQuery JavaScript Library

Jump to: navigation, search


« Back to UI/Datepicker

$.datepicker.formatDate( format, date, [settings] )

Format a date into a string value with a specified format.
The format can be combinations of the following:
  • d - day of month (no leading zero)
  • dd - day of month (two digit)
  • D - day name short
  • DD - day name long
  • m - month of year (no leading zero)
  • mm - month of year (two digit)
  • M - month name short
  • MM - month name long
  • y - year (two digit)
  • yy - year (four digit)
  • '...' - literal text
  • '' - single quote
  • anything else - literal text
Since v3.1.
Arguments:

formatString
The format to use in presenting the date.
dateDate
The date value to be displayed.
settings (Optional)Object
Additional parameters for formatting the date. All are optional and default to the datapicker defaults, which are usually standard English.

Since v3.4 - prior to this these settings were separate parameters.
Attributes include:
dayNamesShort (String[7]) - the short names for the days of the week, starting at Sunday.
dayNames (String[7]) - the long names for the days of the week, starting at Sunday.
monthNamesShort (String[12]) - the short names for the months of the year.
monthNames (String[12]) - the long names for the months of the year.


Examples:
Display the date in ISO format. Produces '2007-01-26'.

$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));

Display the date in expanded French format. Produces 'Samedi, Juillet 14, 2007'.

$.datepicker.formatDate('DD, MM d, yy', new Date(2007, 7 - 1, 14), {dayNamesShort: $.datepicker.regional['fr'].dayNamesShort, dayNames: $.datepicker.regional['fr'].dayNames, monthNamesShort: $.datepicker.regional['fr'].monthNamesShort, monthNames: $.datepicker.regional['fr'].monthNames});

NameType