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 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
# sec-get-temporal.plaindate.prototype.era

Browser compatibility

See also

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant