Temporal.PlainDate.prototype.era

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 "ce" or "bce".

Value

All specified calendars have eras fully defined by the spec.

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, the "ad" and "bc" aliases are also accepted for the "ce" and "bce" eras of the gregory or japanese calendars.

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

Examples

undefined

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); // ce

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

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

See also