Top Description Fields Constructors Methods
java.time.chrono

public final Class JapaneseEra

extends Object
implements Era, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.time.chrono.Era, java.time.temporal.TemporalAdjuster, java.time.temporal.TemporalAccessor
Static Imports
java.time.chrono.JapaneseDate.MEIJI_6_ISODATE, java.time.temporal.ChronoField.ERA

An era in the Japanese Imperial calendar system.

The Japanese government defines the official name and start date of each era. Eras are consecutive and their date ranges do not overlap, so the end date of one era is always the day before the start date of the next era.

The Java SE Platform supports all eras defined by the Japanese government, beginning with the Meiji era. Each era is identified in the Platform by an integer value and a name. The of(int) and valueOf(String) methods may be used to obtain a singleton instance of JapaneseEra for each era. The values() method returns the singleton instances of all supported eras.

For convenience, this class declares a number of public static final fields that refer to singleton instances returned by the values() method.

API Note

The fields declared in this class may evolve over time, in line with the results of the values() method. However, there is not necessarily a 1:1 correspondence between the fields and the singleton instances.

API Note

The Japanese government may announce a new era and define its start date but not its official name. In this scenario, the singleton instance that represents the new era may return a name that is not stable until the official name is defined. Developers should exercise caution when relying on the name returned by any singleton instance that does not correspond to a public static final field.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Field Summary

Modifier and TypeField and Description
pack-priv static final Era[]
pack-priv static final int
private final transient int
eraValue

The era value.

public static final JapaneseEra
HEISEI

The singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30) which has the value 2.

private static final JapaneseEra[]
public static final JapaneseEra
MEIJI

The singleton instance for the 'Meiji' era (1868-01-01 - 1912-07-29) which has the value -1.

private static final int
public static final JapaneseEra
REIWA

The singleton instance for the 'Reiwa' era (2019-05-01 - ) which has the value 3.

private static final long
serialVersionUID

Serialization version.

public static final JapaneseEra
SHOWA

The singleton instance for the 'Showa' era (1926-12-25 - 1989-01-07) which has the value 1.

private final transient LocalDate
public static final JapaneseEra
TAISHO

The singleton instance for the 'Taisho' era (1912-07-30 - 1926-12-24) which has the value 0.

Constructor Summary

AccessConstructor and Description
private
JapaneseEra(int
the era value, validated
eraValue
,
LocalDate
the date representing the first date of the era, validated not null
since
)

Creates an instance.

Method Summary

Modifier and TypeMethod and Description
pack-priv static JapaneseEra

Returns:

the Era singleton, never null
from
(LocalDate
the date, not null
date
)

Obtains an instance of JapaneseEra from a date.

pack-priv String
public String
getDisplayName(TextStyle
the style of the text required, not null
style
,
Locale
the locale to use, not null
locale
)

Overrides default java.time.chrono.Era.getDisplayName.

Gets the textual representation of this era.
pack-priv String
pack-priv Era

Returns:

the Sun private Era instance for this JapaneseEra.
getPrivateEra
()

Returns the Sun private Era instance corresponding to this JapaneseEra.

public int

Returns:

the era value
getValue
()

Implements java.time.chrono.Era.getValue.

Gets the numeric era int value.
public static JapaneseEra

Returns:

the JapaneseEra singleton, not null
of
(int
the era to represent
japaneseEra
)

Obtains an instance of JapaneseEra from an int value.

private static int

Returns:

the index of the current Era
ordinal
(int
the era value to convert to the index
eraValue
)

Returns the index into the arrays from the Era value.

pack-priv static Era
public ValueRange

Returns:

the range of valid values for the field, not null
range
(TemporalField
the field to query the range for, not null
field
)

Overrides default java.time.chrono.Era.range.

Gets the range of valid values for the specified field.
pack-priv static JapaneseEra
private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

pack-priv static JapaneseEra
toJapaneseEra(Era privateEra)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static JapaneseEra

Returns:

the JapaneseEra singleton, never null
valueOf
(String
the japaneseEra name; non-null
japaneseEra
)

Returns the JapaneseEra with the name.

public static JapaneseEra[]

Returns:

an array of JapaneseEras
values
()

Returns an array of JapaneseEras.

pack-priv void
private Object

Returns:

the instance of Ser, not null
writeReplace
()

Writes the object using a dedicated serialized form.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ERA_CONFIGback to summary
pack-priv static final Era[] ERA_CONFIG
ERA_OFFSETback to summary
pack-priv static final int ERA_OFFSET
eraValueback to summary
private final transient int eraValue

The era value.

HEISEIback to summary
public static final JapaneseEra HEISEI

The singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30) which has the value 2.

KNOWN_ERASback to summary
private static final JapaneseEra[] KNOWN_ERAS
MEIJIback to summary
public static final JapaneseEra MEIJI

The singleton instance for the 'Meiji' era (1868-01-01 - 1912-07-29) which has the value -1.

N_ERA_CONSTANTSback to summary
private static final int N_ERA_CONSTANTS
REIWAback to summary
public static final JapaneseEra REIWA

The singleton instance for the 'Reiwa' era (2019-05-01 - ) which has the value 3. The end date of this era is not specified, unless the Japanese Government defines it.

Since
13
serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

Annotations
@Serial
SHOWAback to summary
public static final JapaneseEra SHOWA

The singleton instance for the 'Showa' era (1926-12-25 - 1989-01-07) which has the value 1.

sinceback to summary
private final transient LocalDate since
TAISHOback to summary
public static final JapaneseEra TAISHO

The singleton instance for the 'Taisho' era (1912-07-30 - 1926-12-24) which has the value 0.

Constructor Detail

JapaneseEraback to summary
private JapaneseEra(int eraValue, LocalDate since)

Creates an instance.

Parameters
eraValue:int

the era value, validated

since:LocalDate

the date representing the first date of the era, validated not null

Method Detail

fromback to summary
pack-priv static JapaneseEra from(LocalDate date)

Obtains an instance of JapaneseEra from a date.

Parameters
date:LocalDate

the date, not null

Returns:JapaneseEra

the Era singleton, never null

getAbbreviationback to summary
pack-priv String getAbbreviation()
getDisplayNameback to summary
public String getDisplayName(TextStyle style, Locale locale)

Overrides default java.time.chrono.Era.getDisplayName.

Doc from java.time.chrono.Era.getDisplayName.

Gets the textual representation of this era.

This returns the textual name used to identify the era, suitable for presentation to the user. The parameters control the style of the returned text and the locale.

If no textual mapping is found then the numeric value is returned.

Parameters
style:TextStyle

the style of the text required, not null

locale:Locale

the locale to use, not null

Returns:String

the text value of the era, not null

Annotations
@Override
getNameback to summary
pack-priv String getName()
getPrivateEraback to summary
pack-priv Era getPrivateEra()

Returns the Sun private Era instance corresponding to this JapaneseEra.

Returns:Era

the Sun private Era instance for this JapaneseEra.

getValueback to summary
public int getValue()

Implements java.time.chrono.Era.getValue.

Gets the numeric era int value.

The SHOWA era that contains 1970-01-01 (ISO calendar system) has the value 1. Later eras are numbered from 2 (HEISEI). Earlier eras are numbered 0 (TAISHO), -1 (MEIJI)).

Returns:int

the era value

Annotations
@Override
ofback to summary
public static JapaneseEra of(int japaneseEra)

Obtains an instance of JapaneseEra from an int value.

  • The value 1 is associated with the 'Showa' era, because it contains 1970-01-01 (ISO calendar system).
  • The values -1 and 0 are associated with two earlier eras, Meiji and Taisho, respectively.
  • A value greater than 1 is associated with a later era, beginning with Heisei (2).

Every instance of JapaneseEra that is returned from the values() method has an int value (available via Era#getValue() which is accepted by this method.

Parameters
japaneseEra:int

the era to represent

Returns:JapaneseEra

the JapaneseEra singleton, not null

Exceptions
DateTimeException:
if the value is invalid
ordinalback to summary
private static int ordinal(int eraValue)

Returns the index into the arrays from the Era value. the eraValue is a valid Era number, -1..2.

Parameters
eraValue:int

the era value to convert to the index

Returns:int

the index of the current Era

privateEraFromback to summary
pack-priv static Era privateEraFrom(LocalDate isoDate)
rangeback to summary
public ValueRange range(TemporalField field)

Overrides default java.time.chrono.Era.range.

Gets the range of valid values for the specified field.

The range object expresses the minimum and maximum valid values for a field. This era is used to enhance the accuracy of the returned range. If it is not possible to return the range, because the field is not supported or for some other reason, an exception is thrown.

If the field is a ChronoField then the query is implemented here. The ERA field returns the range. All other ChronoField instances will throw an UnsupportedTemporalTypeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.rangeRefinedBy(TemporalAccessor) passing this as the argument. Whether the range can be obtained is determined by the field.

The range of valid Japanese eras can change over time due to the nature of the Japanese calendar system.

Parameters
field:TemporalField

the field to query the range for, not null

Returns:ValueRange

the range of valid values for the field, not null

Annotations
@Override
Exceptions
DateTimeException:
if the range for the field cannot be obtained
UnsupportedTemporalTypeException:
if the unit is not supported
readExternalback to summary
pack-priv static JapaneseEra readExternal(DataInput in) throws IOException
readObjectback to summary
private void readObject(ObjectInputStream s) throws InvalidObjectException

Defend against malicious streams.

Parameters
s:ObjectInputStream

the stream to read

Annotations
@Serial
Exceptions
InvalidObjectException:
always
toJapaneseEraback to summary
pack-priv static JapaneseEra toJapaneseEra(Era privateEra)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
valueOfback to summary
public static JapaneseEra valueOf(String japaneseEra)

Returns the JapaneseEra with the name.

The string must match exactly the name of the era. (Extraneous whitespace characters are not permitted.)

Valid era names are the names of eras returned from values().

Parameters
japaneseEra:String

the japaneseEra name; non-null

Returns:JapaneseEra

the JapaneseEra singleton, never null

Exceptions
IllegalArgumentException:
if there is not JapaneseEra with the specified name
valuesback to summary
public static JapaneseEra[] values()

Returns an array of JapaneseEras. The array may contain eras defined by the Japanese government beyond the known era singletons.

This method may be used to iterate over the JapaneseEras as follows:

for (JapaneseEra c : JapaneseEra.values())
    System.out.println(c);
Returns:JapaneseEra[]

an array of JapaneseEras

writeExternalback to summary
pack-priv void writeExternal(DataOutput out) throws IOException
writeReplaceback to summary
private Object writeReplace()

Writes the object using a dedicated serialized form.

Returns:Object

the instance of Ser, not null

Annotations
@Serial
Serial data
 out.writeByte(5);        // identifies a JapaneseEra
 out.writeInt(getValue());