Class JapaneseCalendar
- java.lang.Object
-
- com.ibm.icu.util.Calendar
-
- com.ibm.icu.util.GregorianCalendar
-
- com.ibm.icu.util.JapaneseCalendar
-
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<Calendar>
public class JapaneseCalendar extends GregorianCalendar
JapaneseCalendaris a subclass ofGregorianCalendarthat 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
ERAfield, 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):
- Java system property
ICU_ENABLE_TENTATIVE_ERA=true. - Environment variable
ICU_ENABLE_TENTATIVE_ERA=true. - 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
Calendar.getInstance(ULocale)passing in aULocalewith the tag"@calendar=japanese".- Author:
- Laura Werner, Alan Liu
- See Also:
GregorianCalendar,Calendar, Serialized Form- Status:
- Stable ICU 2.8.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.ibm.icu.util.Calendar
Calendar.FormatConfiguration, Calendar.WeekData
-
-
Field Summary
Fields Modifier and Type Field Description static intCURRENT_ERAstatic intHEISEIConstant for the era starting on Jan. 7, 1989 AD.static intMEIJIConstant for the era starting on Sept. 8, 1868 AD.static intREIWAConstant for the era starting on May 1, 2019 AD.static intSHOWAConstant for the era starting on Dec. 25, 1926 AD.static intTAISHOConstant for the era starting on July 30, 1912 AD.-
Fields inherited from class com.ibm.icu.util.GregorianCalendar
AD, BC, invertGregorian, isGregorian
-
Fields inherited from class com.ibm.icu.util.Calendar
AM, AM_PM, APRIL, AUGUST, BASE_FIELD_COUNT, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DOW_LOCAL, DST_OFFSET, EPOCH_JULIAN_DAY, ERA, EXTENDED_YEAR, FEBRUARY, FRIDAY, GREATEST_MINIMUM, HOUR, HOUR_OF_DAY, INTERNALLY_SET, IS_LEAP_MONTH, JAN_1_1_JULIAN_DAY, JANUARY, JULIAN_DAY, JULY, JUNE, LEAST_MAXIMUM, MARCH, MAX_DATE, MAX_FIELD_COUNT, MAX_JULIAN, MAX_MILLIS, MAXIMUM, MAY, MILLISECOND, MILLISECONDS_IN_DAY, MIN_DATE, MIN_JULIAN, MIN_MILLIS, MINIMUM, MINIMUM_USER_STAMP, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ORDINAL_MONTH, PM, RESOLVE_REMAP, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, UNSET, WALLTIME_FIRST, WALLTIME_LAST, WALLTIME_NEXT_VALID, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, WEEKDAY, WEEKEND, WEEKEND_CEASE, WEEKEND_ONSET, YEAR, YEAR_WOY, ZONE_OFFSET
-
-
Constructor Summary
Constructors Constructor Description JapaneseCalendar()Constructs a defaultJapaneseCalendarusing the current time in the default time zone with the default locale.JapaneseCalendar(int year, int month, int date)Constructs aJapaneseCalendarwith the given date set in the default time zone with the default locale.JapaneseCalendar(int era, int year, int month, int date)Constructs aJapaneseCalendarwith the given date set in the default time zone with the default locale.JapaneseCalendar(int year, int month, int date, int hour, int minute, int second)Constructs aJapaneseCalendarwith the given date and time set for the default time zone with the default locale.JapaneseCalendar(TimeZone zone)Constructs aJapaneseCalendarbased on the current time in the given time zone with the default locale.JapaneseCalendar(TimeZone zone, ULocale locale)Constructs aJapaneseCalendarbased on the current time in the given time zone with the given locale.JapaneseCalendar(TimeZone zone, Locale aLocale)Constructs aJapaneseCalendarbased on the current time in the given time zone with the given locale.JapaneseCalendar(ULocale locale)Constructs aJapaneseCalendarbased on the current time in the default time zone with the given locale.JapaneseCalendar(Date date)Constructs aJapaneseCalendarwith the given date set in the default time zone with the default locale.JapaneseCalendar(Locale aLocale)Constructs aJapaneseCalendarbased on the current time in the default time zone with the given locale.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanenableTentativeEra()Deprecated.This API is ICU internal only.intgetActualMaximum(int field)Return the maximum value that this field could have, given the current date.protected intgetDefaultDayInMonth(int extendedYear, int month)Called by handleComputeJulianDay.protected intgetDefaultMonthInYear(int extendedYear)Called by handleComputeJulianDay.StringgetType()[icu] Returns the calendar type name string for this Calendar object.protected voidhandleComputeFields(int julianDay)Override Calendar to compute several fields specific to the hybrid Gregorian-Julian calendar system.protected inthandleGetExtendedYear()Returns the extended year defined by the current fields.protected inthandleGetLimit(int field, int limitType)Override GregorianCalendar.booleanhaveDefaultCentury()Deprecated.This API is ICU internal only.protected booleanisEra0CountingBackward()Deprecated.This API is ICU internal only.-
Methods inherited from class com.ibm.icu.util.GregorianCalendar
clone, getActualMinimum, getGregorianChange, handleComputeJulianDay, handleComputeMonthStart, handleGetMonthLength, handleGetYearLength, hashCode, isEquivalentTo, isLeapYear, roll, setGregorianChange
-
Methods inherited from class com.ibm.icu.util.Calendar
add, after, before, clear, clear, compareTo, complete, computeFields, computeGregorianFields, computeGregorianMonthStart, computeJulianDay, computeMillisInDay, computeMillisInDayLong, computeTime, computeZoneOffset, computeZoneOffset, equals, fieldDifference, fieldName, floorDivide, floorDivide, floorDivide, floorDivide, get, getAvailableLocales, getAvailableULocales, getDateAtTimePattern, getDateTimeFormat, getDateTimeFormat, getDateTimePattern, getDayOfWeekType, getDisplayName, getDisplayName, getFieldCount, getFieldResolutionTable, getFirstDayOfWeek, getGreatestMinimum, getGregorianDayOfMonth, getGregorianDayOfYear, getGregorianMonth, getGregorianYear, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getKeywordValuesForLocale, getLeastMaximum, getLimit, getLocale, getMaximum, getMinimalDaysInFirstWeek, getMinimum, getRelatedYear, getRelatedYearDifference, getRepeatedWallTimeOption, getSkippedWallTimeOption, getStamp, getTemporalMonthCode, getTime, getTimeInMillis, getTimeZone, getWeekData, getWeekDataForRegion, getWeekendTransition, gregorianMonthLength, gregorianPreviousMonthLength, handleCreateFields, handleGetDateFormat, handleGetDateFormat, handleGetDateFormat, handleGetDateFormat, inTemporalLeapYear, internalGet, internalGet, internalGetMonth, internalGetMonth, internalGetTimeInMillis, internalSet, isGregorianLeapYear, isLenient, isSet, isWeekend, isWeekend, julianDayToDayOfWeek, julianDayToMillis, millisToJulianDay, newerField, newestStamp, pinField, prepareGetActual, resolveFields, roll, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setRelatedYear, setRepeatedWallTimeOption, setSkippedWallTimeOption, setTemporalMonthCode, setTime, setTimeInMillis, setTimeZone, setWeekData, toString, validateField, validateField, validateFields, weekNumber, weekNumber
-
-
-
-
Field Detail
-
CURRENT_ERA
public static final int CURRENT_ERA
- Status:
- Stable ICU 2.8.
-
MEIJI
public static final int MEIJI
Constant for the era starting on Sept. 8, 1868 AD.- Status:
- Stable ICU 2.8.
-
TAISHO
public static final int TAISHO
Constant for the era starting on July 30, 1912 AD.- Status:
- Stable ICU 2.8.
-
SHOWA
public static final int SHOWA
Constant for the era starting on Dec. 25, 1926 AD.- Status:
- Stable ICU 2.8.
-
HEISEI
public static final int HEISEI
Constant for the era starting on Jan. 7, 1989 AD.- Status:
- Stable ICU 2.8.
-
REIWA
public static final int REIWA
Constant for the era starting on May 1, 2019 AD.- Status:
- Stable ICU 64.
-
-
Constructor Detail
-
JapaneseCalendar
public JapaneseCalendar()
Constructs a defaultJapaneseCalendarusing the current time in the default time zone with the default locale.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(TimeZone zone)
Constructs aJapaneseCalendarbased on the current time in the given time zone with the default locale.- Parameters:
zone- the given time zone.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(Locale aLocale)
Constructs aJapaneseCalendarbased on the current time in the default time zone with the given locale.- Parameters:
aLocale- the given locale.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(ULocale locale)
Constructs aJapaneseCalendarbased on the current time in the default time zone with the given locale.- Parameters:
locale- the given ulocale.- Status:
- Stable ICU 3.2.
-
JapaneseCalendar
public JapaneseCalendar(TimeZone zone, Locale aLocale)
Constructs aJapaneseCalendarbased on the current time in the given time zone with the given locale.- Parameters:
zone- the given time zone.aLocale- the given locale.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(TimeZone zone, ULocale locale)
Constructs aJapaneseCalendarbased on the current time in the given time zone with the given locale.- Parameters:
zone- the given time zone.locale- the given ulocale.- Status:
- Stable ICU 3.2.
-
JapaneseCalendar
public JapaneseCalendar(Date date)
Constructs aJapaneseCalendarwith the given date set in the default time zone with the default locale.- Parameters:
date- The date to which the new calendar is set.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(int era, int year, int month, int date)Constructs aJapaneseCalendarwith the given date set in the default time zone with the default locale.- Parameters:
era- The imperial era used to set the calendar'sERAfield. Eras are numbered starting with the Tenki era, which began in 1053 AD Gregorian, as era zero. Recent eras can be specified using the constantsMEIJI(which started in 1868 AD),TAISHO(1912 AD),SHOWA(1926 AD), andHEISEI(1989 AD).year- The value used to set the calendar'sYEARfield, in terms of the era.month- The value used to set the calendar'sMONTHfield. The value is 0-based. e.g., 0 for January.date- The value used to set the calendar's DATE field.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(int year, int month, int date)Constructs aJapaneseCalendarwith the given date set in the default time zone with the default locale.- Parameters:
year- The value used to set the calendar'sYEARfield, in the era Heisei, the most current at the time this class was last updated.month- The value used to set the calendar'sMONTHfield. The value is 0-based. e.g., 0 for January.date- The value used to set the calendar'sDATEfield.- Status:
- Stable ICU 2.8.
-
JapaneseCalendar
public JapaneseCalendar(int year, int month, int date, int hour, int minute, int second)Constructs aJapaneseCalendarwith the given date and time set for the default time zone with the default locale.- Parameters:
year- The value used to set the calendar'sYEARtime field, in the era Heisei, the most current at the time of this writing.month- The value used to set the calendar'sMONTHtime field. The value is 0-based. e.g., 0 for January.date- The value used to set the calendar'sDATEtime field.hour- The value used to set the calendar'sHOUR_OF_DAYtime field.minute- The value used to set the calendar'sMINUTEtime field.second- The value used to set the calendar'sSECONDtime field.- Status:
- Stable ICU 2.8.
-
-
Method Detail
-
enableTentativeEra
@Deprecated public static boolean enableTentativeEra()
Deprecated.This API is ICU internal only.Check environment variable that enables use of future eras.- Status:
- Internal. This API is ICU internal only.
-
handleGetExtendedYear
protected int handleGetExtendedYear()
Description copied from class:CalendarReturns 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.- Overrides:
handleGetExtendedYearin classGregorianCalendar- Returns:
- the extended year
- Status:
- Stable ICU 2.8.
-
getDefaultMonthInYear
protected int getDefaultMonthInYear(int extendedYear)
Called by handleComputeJulianDay. Returns the default month (0-based) for the year, taking year and era into account. Defaults to 0 (JANUARY) for Gregorian.- Overrides:
getDefaultMonthInYearin classCalendar- Parameters:
extendedYear- the extendedYear, as returned by handleGetExtendedYear- Returns:
- the default month
- See Also:
Calendar.MONTH- Status:
- Draft ICU 3.6 (retain).
-
getDefaultDayInMonth
protected int getDefaultDayInMonth(int extendedYear, int month)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.- Overrides:
getDefaultDayInMonthin classCalendar- Parameters:
extendedYear- the extendedYear, as returned by handleGetExtendedYearmonth- the month, as returned by getDefaultMonthInYear- Returns:
- the default day of the month
- See Also:
Calendar.DAY_OF_MONTH- Status:
- Draft ICU 3.6 (retain).
-
handleComputeFields
protected void handleComputeFields(int julianDay)
Description copied from class:GregorianCalendarOverride 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
- Overrides:
handleComputeFieldsin classGregorianCalendar- Status:
- Stable ICU 2.8.
-
handleGetLimit
protected int handleGetLimit(int field, int limitType)Override GregorianCalendar. We should really handle YEAR_WOY and EXTENDED_YEAR here too to implement the 1..5000000 range, but it's not critical.- Overrides:
handleGetLimitin classGregorianCalendar- Parameters:
field- one of the above field numberslimitType- one ofMINIMUM,GREATEST_MINIMUM,LEAST_MAXIMUM, orMAXIMUM- Status:
- Stable ICU 2.8.
-
getType
public String 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
- Overrides:
getTypein classGregorianCalendar- Returns:
- legacy calendar type name string
- Status:
- Stable ICU 3.8.
-
haveDefaultCentury
@Deprecated public boolean 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 returnstrue. A subclass may returnfalseif such practice is not applicable (for example, Chinese calendar and Japanese calendar).- Overrides:
haveDefaultCenturyin classCalendar- Returns:
trueif this calendar has a default century.- Status:
- Internal. This API is ICU internal only.
-
getActualMaximum
public int getActualMaximum(int field)
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.- Overrides:
getActualMaximumin classGregorianCalendar- Parameters:
field- the field whose maximum is desired- Returns:
- the maximum of the given field for the current date of this calendar
- See Also:
Calendar.getMaximum(int),Calendar.getLeastMaximum(int)- Status:
- Stable ICU 4.0.
-
isEra0CountingBackward
@Deprecated protected boolean isEra0CountingBackward()
Deprecated.This API is ICU internal only.The year in this calendar is counting from 1 backward if the era is 0.- Overrides:
isEra0CountingBackwardin classGregorianCalendar- Returns:
- The year in era 0 of this calendar is counting backward from 1.
- Status:
- Internal. This API is ICU internal only.
-
-