Skip to content

DateFormatter setLocaleSettings

MarkusWME edited this page May 21, 2016 · 3 revisions

setLocaleSettings

DateFormatter - setLocaleSettings

Description

void setLocaleSettings(object localeSettings)

This function allows to set custom locale settings. This allows to localize the output of some other functions.

Parameters

Parameter Description
localeSettings The locale settings object which contains all locale settings that are needed. The parameter could also be given as a string that could be parsed to a JSON object.

The settings object has the following fields:

  • days: Array of day names (starting with Monday and ending with Sunday).
  • daysShort: Array of day name abbreviations (starting with the abbreviation of Monday and ending with the abbreviation of Sunday).
  • dayAppendix: Array of the day appendices (starting with the appendix of the first and ending with the appendix of the 31st day).
  • months: Array of month names (starting with January and ending with December).
  • monthsShort: Array of month name abbreviations (starting with the abbreviation of January and ending with the abbreviation of Sunday).
  • ampm: Array for the definition of the AM and PM texts.

See the examples for more information about the format of the settings object.

Return value

This function doesn't return a value.

Errors/Exceptions

If the localeSettings parameter is neither an object nor a string a TypeError exception will be thrown. In that case the localeSettings attribute of the DateFormatter will be set to null.

Examples

// Initialize the locale settings object
var locales = {
    days: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
    daysShort: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    dayAppendix: [
        'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
        'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th'
    ],
    months: [
        'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November',
        'December'
    ],
    monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    ampm: ['am', 'pm']
};

// Initialize a DateFormatter and set the locales
var dateFormatter = new DateFormatter();
dateFormatter.setLocaleSettings(locales);

This will initialize basic localization for the English language.