Temporal.PlainDate.prototype.era

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 era accessor property of Temporal.PlainDate instances returns a calendar-specific lowercase string representing the era of this date, or undefined if the calendar does not use eras (e.g. ISO 8601). era and eraYear together uniquely identify a year in a calendar, in the same way that year does. It is calendar-dependent. For Gregorian, it is either "gregory" or "gregory-inverse".

The set accessor of era is undefined. You cannot change this property directly. Use the with() method to create a new Temporal.PlainDate object with the desired new value. When setting eras, each code may have some aliases; for example, "ce" and "ad" are equivalent to "gregory", and "bce" and "bc" are equivalent to "gregory-inverse".

Note: This string is not intended for display to users. Use toLocaleString() with the appropriate options to get a localized string.

Examples

Using era

js
const date = Temporal.PlainDate.from("2021-07-01"); // ISO 8601 calendar
console.log(date.era); // undefined

const date2 = Temporal.PlainDate.from("2021-07-01[u-ca=gregory]");
console.log(date2.era); // gregory

const date3 = Temporal.PlainDate.from("-002021-07-01[u-ca=gregory]");
console.log(date3.era); // gregory-inverse

const date4 = Temporal.PlainDate.from("2021-07-01[u-ca=japanese]");
console.log(date4.era); // reiwa

Changing era

You can only set era for calendars that support them. For example, the ISO 8601 calendar does not have eras. Note that you must provide era and eraYear together.

js
const date = Temporal.PlainDate.from("2021-07-01[u-ca=gregory]");
const newDate = date.with({ era: "bc", eraYear: 100 });
console.log(newDate.toString()); // -000099-07-01[u-ca=gregory]

const date2 = Temporal.PlainDate.from("2021-07-01[u-ca=japanese]");
const newDate2 = date2.with({ era: "meiji", eraYear: 1 });
console.log(newDate2.toString()); // 1868-07-01[u-ca=japanese]

Specifications

Specification
Temporal proposal
# sec-get-temporal.plaindate.prototype.era

Browser compatibility

BCD tables only load in the browser

See also