Module java.base
Package java.text

Class DateFormat.Field

All Implemented Interfaces:
Serializable
Enclosing class:
DateFormat

public static class DateFormat.Field
extends Format.Field
Defines constants that are used as attribute keys in the AttributedCharacterIterator returned from DateFormat.formatToCharacterIterator and as field identifiers in FieldPosition.

The class also provides two methods to map between its constants and the corresponding Calendar constants.

Since:
1.4
See Also:
Calendar, Serialized Form
  • Field Details

  • Constructor Details

    • Field

      protected Field​(String name, int calendarField)
      Creates a Field.
      Parameters:
      name - the name of the Field
      calendarField - the Calendar constant this Field corresponds to; any value, even one outside the range of legal Calendar values may be used, but -1 should be used for values that don't correspond to legal Calendar values
  • Method Details

    • ofCalendarField

      public static DateFormat.Field ofCalendarField​(int calendarField)
      Returns the Field constant that corresponds to the Calendar constant calendarField. If there is no direct mapping between the Calendar constant and a Field, null is returned.
      Parameters:
      calendarField - Calendar field constant
      Returns:
      Field instance representing calendarField.
      Throws:
      IllegalArgumentException - if calendarField is not the value of a Calendar field constant.
      See Also:
      Calendar
    • getCalendarField

      public int getCalendarField()
      Returns the Calendar field associated with this attribute. For example, if this represents the hours field of a Calendar, this would return Calendar.HOUR. If there is no corresponding Calendar constant, this will return -1.
      Returns:
      Calendar constant for this field
      See Also:
      Calendar
    • readResolve

      protected Object readResolve() throws InvalidObjectException
      Resolves instances being deserialized to the predefined constants.
      Overrides:
      readResolve in class AttributedCharacterIterator.Attribute
      Returns:
      resolved DateFormat.Field constant
      Throws:
      InvalidObjectException - if the constant could not be resolved.