Top Description Fields Constructors Methods
com.ibm.icu.util

public Class JapaneseCalendar

extends GregorianCalendar
Class Inheritance
Imports
java.util.Date, .Locale, com.ibm.icu.impl.CalType, .EraRules

JapaneseCalendar is a subclass of GregorianCalendar that numbers years and eras based on the reigns of the Japanese emperors. The Japanese calendar is identical to the Gregorian calendar in all respects except for the year and era. The ascension of each emperor to the throne begins a new era, and the years of that era are numbered starting with the year of ascension as year 1.

Note that in the year of an imperial ascension, there are two possible sets of year and era values: that for the old era and for the new. For example, a new era began on January 7, 1989 AD. Strictly speaking, the first six days of that year were in the Showa era, e.g. "January 6, 64 Showa", while the rest of the year was in the Heisei era, e.g. "January 7, 1 Heisei". This class handles this distinction correctly when computing dates. However, in lenient mode either form of date is acceptable as input.

In modern times, eras have started on January 8, 1868 AD, Gregorian (Meiji), July 30, 1912 (Taisho), December 25, 1926 (Showa), and January 7, 1989 (Heisei). Constants for these eras, suitable for use in the ERA field, are provided in this class. Note that the number used for each era is more or less arbitrary. Currently, the era starting in 645 AD is era #0; however this may change in the future. Use the predefined constants rather than using actual, absolute numbers.

Since ICU4J 63, start date of each era is imported from CLDR. CLDR era data may contain tentative era in near future with placeholder names. By default, such era data is not enabled. ICU4J users who want to test the behavior of the future era can enable this by one of following settings (in the priority order):

  1. Java system property ICU_ENABLE_TENTATIVE_ERA=true.
  2. Environment variable ICU_ENABLE_TENTATIVE_ERA=true.
  3. Java system property jdk.calendar.japanese.supplemental.era=xxx. (Note: This configuration is used for specifying a new era's start date and names in OpenJDK. ICU4J implementation enables the CLDR tentative era when this property is defined, but it does not use the start date and names specified by the property value.)

This class should not be subclassed.

JapaneseCalendar usually should be instantiated using com.ibm.icu.util.Calendar#getInstance(ULocale) passing in a ULocale with the tag "@calendar=japanese".

Authors
Laura Werner, Alan Liu
ICU Status
Stable since ICU 2.8.
See Also
com.ibm.icu.util.GregorianCalendar, com.ibm.icu.util.Calendar

Field Summary

Modifier and TypeField and Description
public static final int
private static final EraRules
private static final int
public static final int
HEISEI

Constant for the era starting on Jan.

public static final int
MEIJI

Constant for the era starting on Sept.

public static final int
REIWA

Constant for the era starting on May 1, 2019 AD.

private static final long
public static final int
SHOWA

Constant for the era starting on Dec.

public static final int
TAISHO

Constant for the era starting on July 30, 1912 AD.

Inherited from com.ibm.icu.util.GregorianCalendar:
ADBCinvertGregorianisGregorian

Constructor Summary

AccessConstructor and Description
public
JapaneseCalendar()

Constructs a default JapaneseCalendar using the current time in the default time zone with the default locale.

public
JapaneseCalendar(TimeZone
the given time zone.
zone
)

Constructs a JapaneseCalendar based on the current time in the given time zone with the default locale.

public
JapaneseCalendar(Locale
the given locale.
aLocale
)

Constructs a JapaneseCalendar based on the current time in the default time zone with the given locale.

public
JapaneseCalendar(ULocale
the given ulocale.
locale
)

Constructs a JapaneseCalendar based on the current time in the default time zone with the given locale.

public
JapaneseCalendar(TimeZone
the given time zone.
zone
,
Locale
the given locale.
aLocale
)

Constructs a JapaneseCalendar based on the current time in the given time zone with the given locale.

public
JapaneseCalendar(TimeZone
the given time zone.
zone
,
ULocale
the given ulocale.
locale
)

Constructs a JapaneseCalendar based on the current time in the given time zone with the given locale.

public
JapaneseCalendar(Date
The date to which the new calendar is set.
date
)

Constructs a JapaneseCalendar with the given date set in the default time zone with the default locale.

public
JapaneseCalendar(int
The imperial era used to set the calendar's ERA field. Eras are numbered starting with the Tenki era, which began in 1053 AD Gregorian, as era zero. Recent eras can be specified using the constants MEIJI (which started in 1868 AD), TAISHO (1912 AD), SHOWA (1926 AD), and HEISEI (1989 AD).
era
,
int
The value used to set the calendar's YEAR field, in terms of the era.
year
,
int
The value used to set the calendar's MONTH field. The value is 0-based. e.g., 0 for January.
month
,
int
The value used to set the calendar's DATE field.
date
)

Constructs a JapaneseCalendar with the given date set in the default time zone with the default locale.

public
JapaneseCalendar(int
The value used to set the calendar's YEAR field, in the era Heisei, the most current at the time this class was last updated.
year
,
int
The value used to set the calendar's MONTH field. The value is 0-based. e.g., 0 for January.
month
,
int
The value used to set the calendar's DATE field.
date
)

Constructs a JapaneseCalendar with the given date set in the default time zone with the default locale.

public
JapaneseCalendar(int
The value used to set the calendar's YEAR time field, in the era Heisei, the most current at the time of this writing.
year
,
int
The value used to set the calendar's MONTH time field. The value is 0-based. e.g., 0 for January.
month
,
int
The value used to set the calendar's DATE time field.
date
,
int
The value used to set the calendar's HOUR_OF_DAY time field.
hour
,
int
The value used to set the calendar's MINUTE time field.
minute
,
int
The value used to set the calendar's SECOND time field.
second
)

Constructs a JapaneseCalendar with the given date and time set for the default time zone with the default locale.

Method Summary

Modifier and TypeMethod and Description
public static boolean
enableTentativeEra()

Deprecated This API is ICU internal only.
Check environment variable that enables use of future eras.
public int
getActualMaximum(int
the field whose maximum is desired
field
)

Overrides com.ibm.icu.util.GregorianCalendar.getActualMaximum.

Return the maximum value that this field could have, given the current date.
protected int

Returns:

the default day of the month
getDefaultDayInMonth
(int
the extendedYear, as returned by handleGetExtendedYear
extendedYear
,
int
the month, as returned by getDefaultMonthInYear
month
)

Overrides com.ibm.icu.util.Calendar.getDefaultDayInMonth.

Called by handleComputeJulianDay.
protected int

Returns:

the default month
getDefaultMonthInYear
(int
the extendedYear, as returned by handleGetExtendedYear
extendedYear
)

Overrides com.ibm.icu.util.Calendar.getDefaultMonthInYear.

Called by handleComputeJulianDay.
public String
protected void
handleComputeFields(int julianDay)

Overrides com.ibm.icu.util.GregorianCalendar.handleComputeFields.

Override Calendar to compute several fields specific to the hybrid Gregorian-Julian calendar system.
protected int
handleGetExtendedYear()

Overrides com.ibm.icu.util.GregorianCalendar.handleGetExtendedYear.

Returns the extended year defined by the current fields.
protected int
handleGetLimit(int
one of the above field numbers
field
,
int
one of MINIMUM, GREATEST_MINIMUM, LEAST_MAXIMUM, or MAXIMUM
limitType
)

Overrides com.ibm.icu.util.GregorianCalendar.handleGetLimit.

Override GregorianCalendar.
public boolean
haveDefaultCentury()

Overrides com.ibm.icu.util.Calendar.haveDefaultCentury.

Deprecated This API is ICU internal only.
Returns if two digit representation of year in this calendar type customarily implies a default century (i.e. 03 -> 2003).
Inherited from com.ibm.icu.util.GregorianCalendar:
getActualMinimumgetGregorianChangehandleComputeJulianDayhandleComputeMonthStarthandleGetMonthLengthhandleGetYearLengthhashCodeinDaylightTimeisEquivalentToisLeapYearrollsetGregorianChange

Field Detail

CURRENT_ERAback to summary
public static final int CURRENT_ERA
ICU Status
Stable since ICU 2.8.
ERA_RULESback to summary
private static final EraRules ERA_RULES
GREGORIAN_EPOCHback to summary
private static final int GREGORIAN_EPOCH
HEISEIback to summary
public static final int HEISEI

Constant for the era starting on Jan. 7, 1989 AD.

ICU Status
Stable since ICU 2.8.
MEIJIback to summary
public static final int MEIJI

Constant for the era starting on Sept. 8, 1868 AD.

ICU Status
Stable since ICU 2.8.
REIWAback to summary
public static final int REIWA

Constant for the era starting on May 1, 2019 AD.

ICU Status
Stable since ICU 64.
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.ibm.icu.util.GregorianCalendar.serialVersionUID.

SHOWAback to summary
public static final int SHOWA

Constant for the era starting on Dec. 25, 1926 AD.

ICU Status
Stable since ICU 2.8.
TAISHOback to summary
public static final int TAISHO

Constant for the era starting on July 30, 1912 AD.

ICU Status
Stable since ICU 2.8.

Constructor Detail

JapaneseCalendarback to summary
public JapaneseCalendar()

Constructs a default JapaneseCalendar using the current time in the default time zone with the default locale.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(TimeZone zone)

Constructs a JapaneseCalendar based on the current time in the given time zone with the default locale.

Parameters
zone:TimeZone

the given time zone.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(Locale aLocale)

Constructs a JapaneseCalendar based on the current time in the default time zone with the given locale.

Parameters
aLocale:Locale

the given locale.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(ULocale locale)

Constructs a JapaneseCalendar based on the current time in the default time zone with the given locale.

Parameters
locale:ULocale

the given ulocale.

ICU Status
Stable since ICU 3.2.
JapaneseCalendarback to summary
public JapaneseCalendar(TimeZone zone, Locale aLocale)

Constructs a JapaneseCalendar based on the current time in the given time zone with the given locale.

Parameters
zone:TimeZone

the given time zone.

aLocale:Locale

the given locale.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(TimeZone zone, ULocale locale)

Constructs a JapaneseCalendar based on the current time in the given time zone with the given locale.

Parameters
zone:TimeZone

the given time zone.

locale:ULocale

the given ulocale.

ICU Status
Stable since ICU 3.2.
JapaneseCalendarback to summary
public JapaneseCalendar(Date date)

Constructs a JapaneseCalendar with the given date set in the default time zone with the default locale.

Parameters
date:Date

The date to which the new calendar is set.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(int era, int year, int month, int date)

Constructs a JapaneseCalendar with the given date set in the default time zone with the default locale.

Parameters
era:int

The imperial era used to set the calendar's ERA field. Eras are numbered starting with the Tenki era, which began in 1053 AD Gregorian, as era zero. Recent eras can be specified using the constants MEIJI (which started in 1868 AD), TAISHO (1912 AD), SHOWA (1926 AD), and HEISEI (1989 AD).

year:int

The value used to set the calendar's YEAR field, in terms of the era.

month:int

The value used to set the calendar's MONTH field. The value is 0-based. e.g., 0 for January.

date:int

The value used to set the calendar's DATE field.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(int year, int month, int date)

Constructs a JapaneseCalendar with the given date set in the default time zone with the default locale.

Parameters
year:int

The value used to set the calendar's YEAR field, in the era Heisei, the most current at the time this class was last updated.

month:int

The value used to set the calendar's MONTH field. The value is 0-based. e.g., 0 for January.

date:int

The value used to set the calendar's DATE field.

ICU Status
Stable since ICU 2.8.
JapaneseCalendarback to summary
public JapaneseCalendar(int year, int month, int date, int hour, int minute, int second)

Constructs a JapaneseCalendar with the given date and time set for the default time zone with the default locale.

Parameters
year:int

The value used to set the calendar's YEAR time field, in the era Heisei, the most current at the time of this writing.

month:int

The value used to set the calendar's MONTH time field. The value is 0-based. e.g., 0 for January.

date:int

The value used to set the calendar's DATE time field.

hour:int

The value used to set the calendar's HOUR_OF_DAY time field.

minute:int

The value used to set the calendar's MINUTE time field.

second:int

The value used to set the calendar's SECOND time field.

ICU Status
Stable since ICU 2.8.

Method Detail

enableTentativeEraback to summary
public static boolean enableTentativeEra()

Deprecated

This API is ICU internal only.

Check environment variable that enables use of future eras.

Annotations
@Deprecated
ICU Status
Internal ICU component.
getActualMaximumback to summary
public int getActualMaximum(int field)

Overrides com.ibm.icu.util.GregorianCalendar.getActualMaximum.

Doc from com.ibm.icu.util.GregorianCalendar.getActualMaximum.

Return the maximum value that this field could have, given the current date. For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, for some years the actual maximum for MONTH is 12, and for others 13.

Parameters
field:int

Doc from com.ibm.icu.util.Calendar.getActualMaximum.

the field whose maximum is desired

Returns:int

Doc from com.ibm.icu.util.Calendar.getActualMaximum.

the maximum of the given field for the current date of this calendar

Annotations
@Override
ICU Status
Stable since ICU 4.0.
getDefaultDayInMonthback to summary
protected int getDefaultDayInMonth(int extendedYear, int month)

Overrides com.ibm.icu.util.Calendar.getDefaultDayInMonth.

Called by handleComputeJulianDay. Returns the default day (1-based) for the month, taking currently-set year and era into account. Defaults to 1 for Gregorian.

Parameters
extendedYear:int

the extendedYear, as returned by handleGetExtendedYear

month:int

the month, as returned by getDefaultMonthInYear

Returns:int

the default day of the month

Annotations
@Override
ICU Status
Draft since ICU 3.6 (retain).
See Also
DAY_OF_MONTH
getDefaultMonthInYearback to summary
protected int getDefaultMonthInYear(int extendedYear)

Overrides com.ibm.icu.util.Calendar.getDefaultMonthInYear.

Called by handleComputeJulianDay. Returns the default month (0-based) for the year, taking year and era into account. Defaults to 0 (JANUARY) for Gregorian.

Parameters
extendedYear:int

the extendedYear, as returned by handleGetExtendedYear

Returns:int

the default month

Annotations
@Override
ICU Status
Draft since ICU 3.6 (retain).
See Also
MONTH
getTypeback to summary
public String getType()

Overrides com.ibm.icu.util.GregorianCalendar.getType.

Doc from com.ibm.icu.util.GregorianCalendar.getType.

ICU

Returns the calendar type name string for this Calendar object. The returned string is the legacy ICU calendar attribute value, for example, "gregorian" or "japanese".

See type="old type name" for the calendar attribute of locale IDs at http://www.unicode.org/reports/tr35/#Key_Type_Definitions

Returns:String

Doc from com.ibm.icu.util.Calendar.getType.

legacy calendar type name string

Annotations
@Override
ICU Status
Stable since ICU 3.8.
handleComputeFieldsback to summary
protected void handleComputeFields(int julianDay)

Overrides com.ibm.icu.util.GregorianCalendar.handleComputeFields.

Doc from com.ibm.icu.util.GregorianCalendar.handleComputeFields.

Override Calendar to compute several fields specific to the hybrid Gregorian-Julian calendar system. These are:

  • ERA
  • YEAR
  • MONTH
  • DAY_OF_MONTH
  • DAY_OF_YEAR
  • EXTENDED_YEAR
Annotations
@Override
ICU Status
Stable since ICU 2.8.
handleGetExtendedYearback to summary
protected int handleGetExtendedYear()

Overrides com.ibm.icu.util.GregorianCalendar.handleGetExtendedYear.

Doc from com.ibm.icu.util.Calendar.handleGetExtendedYear.

Returns the extended year defined by the current fields. This will use the EXTENDED_YEAR field or the YEAR and supra-year fields (such as ERA) specific to the calendar system, depending on which set of fields is newer.

Returns:int

the extended year

Annotations
@Override
ICU Status
Stable since ICU 2.8.
handleGetLimitback to summary
protected int handleGetLimit(int field, int limitType)

Overrides com.ibm.icu.util.GregorianCalendar.handleGetLimit.

Override GregorianCalendar. We should really handle YEAR_WOY and EXTENDED_YEAR here too to implement the 1..5000000 range, but it's not critical.

Parameters
field:int

Doc from com.ibm.icu.util.Calendar.handleGetLimit.

one of the above field numbers

limitType:int

Doc from com.ibm.icu.util.Calendar.handleGetLimit.

one of MINIMUM, GREATEST_MINIMUM, LEAST_MAXIMUM, or MAXIMUM

Annotations
@Override
@SuppressWarnings:fallthrough
ICU Status
Stable since ICU 2.8.
haveDefaultCenturyback to summary
public boolean haveDefaultCentury()

Overrides com.ibm.icu.util.Calendar.haveDefaultCentury.

Doc from com.ibm.icu.util.Calendar.haveDefaultCentury.

Deprecated

This API is ICU internal only.

Returns if two digit representation of year in this calendar type customarily implies a default century (i.e. 03 -> 2003). The default implementation returns true. A subclass may return false if such practice is not applicable (for example, Chinese calendar and Japanese calendar).

Returns:boolean

true if this calendar has a default century.

Annotations
@Override
@Deprecated
ICU Status
Internal ICU component.