Temporal.PlainYearMonth.prototype.calendarId

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The calendarId accessor property of Temporal.PlainYearMonth instances returns a string representing the calendar used to interpret the internal ISO 8601 date.

For a list of commonly supported values, see Intl.Locale.prototype.getCalendars().

The set accessor of calendarId is undefined. You cannot change this property directly. There's no obvious way to create a new Temporal.PlainYearMonth object with a different calendar that represents the same year-month, so you need to convert it to a Temporal.PlainDate object first using toPlainDate(), change the calendar, and then convert it back.

Examples

Using calendarId

js
const ym = Temporal.PlainYearMonth.from("2021-07");
console.log(ym.calendarId); // "iso8601"; default

const ym2 = Temporal.PlainYearMonth.from("2021-07-01[u-ca=chinese]");
console.log(ym2.calendarId); // "chinese"

Changing calendarId

js
const ym = Temporal.PlainYearMonth.from("2021-07");
const newYM = ym
  .toPlainDate({ day: 1 })
  .withCalendar("chinese")
  .toPlainYearMonth();
console.log(newYM.year, newYM.monthCode); // 2021 "M05"

const newYM2 = ym
  .toPlainDate({ day: 31 })
  .withCalendar("chinese")
  .toPlainYearMonth();
console.log(newYM2.year, newYM2.monthCode); // 2021 "M06"

Specifications

Specification
Temporal proposal
# sec-get-temporal.plainyearmonth.prototype.calendarid

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
calendarId
Experimental

Legend

Tip: you can click/tap on a cell for more information.

No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
User must explicitly enable this feature.

See also