This feature is not Baseline because it does not work in some of the most widely-used browsers.
The toLocaleString() method of Temporal.PlainYearMonth instances returns a string with a language-sensitive representation of this year-month. In implementations with Intl.DateTimeFormat API support, this method delegates to Intl.DateTimeFormat.
Every time toLocaleString is called, it has to perform a search in a big database of localization strings, which is potentially inefficient. When the method is called many times with the same arguments, it is better to create an Intl.DateTimeFormat object and use its format() method, because a DateTimeFormat object remembers the arguments passed to it and may decide to cache a slice of the database, so future format calls can search for localization strings within a more constrained context.
toLocaleString() toLocaleString(locales) toLocaleString(locales, options)
The locales and options parameters 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 return the exact same string as toString(), ignoring both parameters.
locales OptionalA string with a BCP 47 language tag, or an array of such strings. Corresponds to the locales parameter of the Intl.DateTimeFormat() constructor.
options OptionalAn object adjusting the output format. Corresponds to the options parameter of the Intl.DateTimeFormat() constructor. The calendar option must be provided with the same value as this year-month's calendar. Regarding the date-time component options and the style shortcuts (dateStyle and timeStyle), the options should follow one of these forms:
year and month will default to "numeric".dateStyle only: it expands to era, year, and month formats.year or month. Only the specified date components will be included in the output.See the Intl.DateTimeFormat() constructor for details on these parameters and how to use them.
A string representing the given year-month according to language-specific conventions.
In implementations with Intl.DateTimeFormat, this is equivalent to new Intl.DateTimeFormat(locales, options).format(yearMonth), where options has been normalized as described above.
Note: Most of the time, the formatting returned by toLocaleString() is consistent. However, the output may vary between implementations, even within the same locale — output variations are by design and allowed by the specification. It may also not be what you expect. For example, the string may use non-breaking spaces or be surrounded by bidirectional control characters. You should not compare the results of toLocaleString() to hardcoded constants.
RangeErrorThrown if any of the options is invalid.
TypeErrorThrown if any of the options is not of the expected type.
Basic use of this method without specifying a locale returns a formatted string in the default locale and with default options.
// Note that just specifying "2021-08" defaults to the ISO 8601 calendar,
// which throws an error if the locale's default calendar is not ISO 8601.
const ym = Temporal.PlainYearMonth.from("2021-08-01[u-ca=gregory]");
console.log(ym.toLocaleString()); // 8/2021 (assuming en-US locale and Gregorian calendar)
If the year-month's calendar doesn't match the locale's default calendar, even when its calendar is iso8601, an explicit calendar option must be provided with the same value.
const ym = Temporal.PlainYearMonth.from("2021-08");
ym.toLocaleString("en-US", { calendar: "iso8601" }); // 2021-08
You can customize which parts of the year-month are included in the output by providing the options parameter.
const ym = Temporal.PlainYearMonth.from("2021-08-01[u-ca=gregory]");
ym.toLocaleString("en-US", { dateStyle: "full" }); // August 2021
ym.toLocaleString("en-US", { year: "2-digit" }); // 21
ym.toLocaleString("en-US", { month: "long" }); // August
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
toLocaleString |
144 | 144 | 139 | No | No | 144 | 139 | No | No | No | 144 | No | ? | 1.40 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainYearMonth/toLocaleString