code: @Override
      public AttributedCharacterIterator formatToCharacterIterator(Object obj) {
          Calendar cal = calendar;
          if (obj instanceof Calendar) {
              cal = (Calendar)obj;
          } else if (obj instanceof Date) {
              calendar.setTime((Date)obj);
          } else if (obj instanceof Number) {
              calendar.setTimeInMillis(((Number)obj).longValue());
          } else {
              throw new IllegalArgumentException("Cannot format given Object as a Date");
          }
          StringBuffer toAppendTo = new StringBuffer();
          FieldPosition pos = new FieldPosition(0);
          List<FieldPosition> attributes = new ArrayList<FieldPosition>();
          format(cal, getContext(DisplayContext.Type.CAPITALIZATION), toAppendTo, pos, attributes);
  
          AttributedString as = new AttributedString(toAppendTo.toString());
  
          // add DateFormat field attributes to the AttributedString
          for (int i = 0; i < attributes.size(); i++) {
              FieldPosition fp = attributes.get(i);
              Format.Field attribute = fp.getFieldAttribute();
              as.addAttribute(attribute, attribute, fp.getBeginIndex(), fp.getEndIndex());
          }
          // return the CharacterIterator from AttributedString
          return as.getIterator();
      }
docs: Format the object to an attributed string, and return the corresponding iterator
  Overrides superclass method.
  
  @param obj The object to format
  @return <code>AttributedCharacterIterator</code> describing the formatted value.