Date.prototype.toLocaleString()
The toLocaleString() method returns a string with a language-sensitive representation of this date. In implementations with Intl.DateTimeFormat API support, this method simply calls Intl.DateTimeFormat.
Syntax
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)
Parameters
The locales and options arguments customize the behavior of the function and let applications specify the language whose formatting conventions should be used.
In implementations that support the Intl.DateTimeFormat API, these parameters correspond exactly to the Intl.DateTimeFormat() constructor's parameters. Implementations without Intl.DateTimeFormat support are asked to ignore both parameters, making the locale used and the form of the string returned entirely implementation-dependent.
localesoptional: A string with a BCP 47 language tag, or an array of such strings. Corresponds to the
localesparameter of theIntl.DateTimeFormat()constructor.In implementations without
Intl.DateTimeFormatsupport, this parameter is ignored and the host's locale is usually used.
optionsoptional: An object adjusting the output format. Corresponds to the
optionsparameter of theIntl.DateTimeFormat()constructor. Ifweekday,year,month,day,dayPeriod,hour,minute,second, andfractionalSecondDigitsare all undefined, thenyear,month,day,hour,minute,secondwill be set to"numeric".In implementations without
Intl.DateTimeFormatsupport, this parameter is ignored.
See the Intl.DateTimeFormat() constructor for details on these parameters and how to use them.
Return value
A string representing the given date according to language-specific conventions.
In implementations with Intl.DateTimeFormat, this is equivalent to new Intl.DateTimeFormat(locales, options).format(date).