Get to know MDN better
Esta página ha sido traducida del inglés por la comunidad. Aprende más y únete a la comunidad de MDN Web Docs.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julio de 2015.
El método toLocaleString() devuelve un cadena con la representación al idioma de la fecha especificada. Los nuevos argumentos locales y options permiten a las aplicaciones especificar el idioma cuyas convenciones de formato deben usarse y personalizar el comportamiento de la función. En implementaciones anteriores, ignoran los argumentos de las configuraciones locales y options , la configuración regional utilizada y la forma de la cadena devuelta dependen completamente de la implementación .
Los argumentos locales y de options personalizan el comportamiento de la función y permiten que las aplicaciones especifiquen el lenguaje cuyas convenciones de formato deben ser utilizadas. En las implementaciones, que ignoran los argumentos, locales y options, el locale utilizado y la forma de la cadena devuelta dependen totalmente de la implementación.
Vea el constructor de Intl.DateTimeFormat() para detalles en esos parametros y como se usan.
El valor por defecto para cada componente date-time es undefined, pero si las propiedades weekday, year, month, day son todas undefined, entonces year, month, y day son asumidas como "numeric".
A string representing the given date according to language-specific conventions.
In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.
The locales and options arguments are not supported in all browsers yet. To check whether an implementation supports them already, you can use the requirement that illegal language tags are rejected with a RangeError exception:
This example shows some of the variations in localized date and time formats. In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument:
The results provided by toLocaleString() can be customized using the options argument:
Most of the time, the formatting returned by toLocaleString() is consistent. However, this might change in the future and isn't guaranteed for all languages — output variations are by design and allowed by the specification. Most notably, the IE and Edge browsers insert bidirectional control characters around dates, so the output text will flow properly when concatenated with other text.
For this reason you cannot expect to be able to compare the results of toLocaleString() to a static value:
Nota: See also this StackOverflow thread for more details and examples.
When formatting large numbers of dates, it is better to create an Intl.DateTimeFormat object and use the function provided by its format property.
| ECMAScript® 2027 Language Specification # sec-date.prototype.tolocalestring |
| ECMAScript® 2027 Internationalization API Specification # sup-date.prototype.tolocalestring |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 11 feb 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.